This document is archived and information here might be outdated. Recommended version. |
Custom graphics.
[Visual Basic .NET] Public Property CustomGraphics As IGraphicElements
[C#] public IGraphicElements CustomGraphics {get; set;}
[C++]
HRESULT get_CustomGraphics(
IGraphicElements** Elements
);
[C++]
HRESULT put_CustomGraphics(
IGraphicElements* Elements
);
[C++] Parameters Elements [out, retval]
Elements is a parameter of type IGraphicElements** Elements [in]
Elements is a parameter of type IGraphicElements*
Use CustomGraphics to display text or geometric shapes on the map. When interacting with the display of labels, CustomGraphics will honor the Feature Weight value for the default graphics layer set in the Label Weight Ranking dialog in the map document. A setting of High, the ArcMap default, will result in labels not drawing within the bounds of the custom graphics. If the Feature Weight for the default graphics layer is None, Low or Medium labels will draw within the bounds of the custom graphics. With None, all labels should display. With Low or Medium, the amount of labels that draw may vary.
Please note that the optimized MapServer only supports the esriSFSSolid style of ISimpleFillSymbol. For other types of fills, use other fill symbol types such as ILineSymbol. For hollow symbols, you should use IColor::NullColor with esriSFSSolid instead of using the esriSFSNull style.
The following sample code shows how to add custom text to your map. It assumes that you already have a valid MapServer, MapDescription and ImageDisplay object, and that you are not working with a server context. However, if you are developing an ArcGIS for Server application using a server context, you should not use New to create local ArcObjects, but you should always create objects within the server by calling CreateObject on IServerContext .
IMapServer mapServer;
IMapDescription mapDesc;
// Create image display
IImageDisplay imageDisplay = new ImageDisplayClass();
imageDisplay.Height = 400;
imageDisplay.Width = 500;
// Create text symbol
ITextSymbol textSymbol = new TextSymbolClass();
// Set Color
IRgbColor color = new RgbColorClass();
color.Blue = 255;
color.UseWindowsDithering = true;
textSymbol.Color = color;
// Set Font
IFontDisp font = (IFontDisp)new stdole.StdFont() ;
font.Name = "Verdana";
font.Size = 20;
textSymbol .Font = font;
// Create text element
ITextElement textElement = new TextElementClass ();
textElement .Text = "Custom Text";
textElement .Symbol = textSymbol ;
// Set position
ILongArray inXValues = new LongArrayClass ();
ILongArray inYValues = new LongArrayClass ();
inXValues.Add(200);
inYValues.Add(250);
IPointCollection pointCollection;
pointCollection = mapServer.ToMapPoints (mapDesc, imageDisplay , inXValues , inYValues );
IPoint point =pointCollection .get_Point (0);
IElement element = (IElement)textElement ;
element.Geometry = point;
// Create custom graphics
IGraphicElements custGraphics = new GraphicElementsClass ();
custGraphics.Add ((IGraphicElement)textElement);
// Add custom graphics to MapDescription
mapDesc.CustomGraphics = custGraphics ;