There are three types of objects: callouts, ellipses, and polygons.
The basic steps to add any symbol to the map are:
1) Create and initialize the object that represents your figure or symbol;
2) Get the enumeration of the objects of type using the CosmeticLayer interface;
3) Get or create the Symbol object, that controls how the figure will be displayed;
4) Set optional attributes such as color, style, or size using auxiliary objects;
5) Add your symbol to the enumeration of the objects of type.
Let's see how to draw the most frequently used object, the Callout object:
Dim oCallout, cLayer, oEnum, oSymbol, iColor, oFont ' step 1 oCallout = new Callout ' define the point on the map where callout will be displayed (pixels) oCallout.setAnchor( map.toMapUnits( 300, 200)) ' step 2 cLayer = map.getCosmeticLayer() oEnum = cLayer.getCallouts() ' step 3 oSymbol = new Symbol ' step 4 iColor = new Color( 255, 0, 0).getRGB() oFont = new TextFont oSymbol.setSize( 20) oSymbol.setColor( Symbol.rmSymbolColor, iColor) oSymbol.setSymbolStyle( "std:star") oFont.setColor( iColor) oFont.setBold( true) oFont.setUnderline( true) oFont.setItalic( true) oFont.setSize( 20) oCallout.setSymbol (oSymbol) oCallout.setOrientation( Callout.rmTopCenter) oCallout.setFont (oFont) ' to get a symbol without any text, omit this step oCallout.setText( "Sample Callout") ' step 5 oEnum.add(oCallout)
The result should look like this:
Here is another example where we draw an ellipse:
Dim oEllipseSymbol, oGeoEllipse, cLayer, oEnum, oSymbol, iColor ' step 1 oEllipseSymbol = new EllipseSymbol oGeoEllipse = new GeoEllipse oGeoEllipse.center = map.toMapUnits( 300, 200) oGeoEllipse.height = map.convertDistance( 120, MeasureUnit.rmPixels, MeasureUnit.rmMapUnits) oGeoEllipse.width = map.convertDistance( 200, MeasureUnit.rmPixels, MeasureUnit.rmMapUnits) oEllipseSymbol.setEllipse (oGeoEllipse) ' step 2 cLayer = map.getCosmeticLayer() oEnum = cLayer.getEllipses() ' step 3 oSymbol = oEllipseSymbol.getSymbol() ' step 4 iColor = new Color(0, 0, 255).getRGB() ' blue oSymbol.setColor(Symbol.rmSymbolColor, iColor) oSymbol.setColor(Symbol.rmBrushColor, iColor) oSymbol.setBrushStyle("brush:bdiagonal") ' step 5 oEnum.add(oEllipseSymbol)
This example shows how to draw a rectangle:
Dim rc, gp, oCLayer, pl, oSymbol, i, iColor ' step 1 rc = new PolygonSymbol() Dim vertex() : ReDim vertex(4) vertex(0) = map.toMapUnits( 125, 300) ' bottom/left vertex(1) = map.toMapUnits( 125, 100) ' top/left vertex(2) = map.toMapUnits( 475, 100) ' top/right vertex(3) = map.toMapUnits( 475, 300) ' bottom/right gp = new GeoPointsImpl() For i = 0 To UBound( vertex) - 1 gp.addPoint( vertex(i).x, vertex(i).y) Next rc.setPoints( gp) ' step 2 oCLayer = map.getCosmeticLayer() pl = oCLayer.getPolygons() ' step 3 oSymbol = rc.getSymbol() ' step 4 iColor = new Color(0, 0, 255).getRGB() ' blue oSymbol.setColor( Symbol.rmBrushColor, iColor) oSymbol.setBrushStyle("brush:bdiagonal") ' step 5 pl.add(rc)C# | JScript.NET