Creating dynamic glyphs
Creation of dynamic glyphs must take place inside one of the dynamic drawing methods; either inside IDynamicLayer.drawDynamicLayer or one of the DynamicDisplayEvents callbacks (IDynamicMapEvents.beforeDraw and IDynamicMapEvents.afterDraw). This is because the creation of a DynamicGlyph is done through the DynamicGlyphFactory, which is a property of the DynamicDisplay where the DynamicDisplay is a parameter of these methods.
Obtaining DynamicGlyphFactory and DynamicSymbolProperties from the DynamicDisplay
It is highly recommended to keep the DynamicGlyphFactory and DynamicSymbolProperties as class members and only get them once from the DynamicDisplay, since they will be used many times throughout the lifetime of the application. See the following:
[Java]
if (bOnce){
//Get the DynamicGlyphFactory from the DynamicDisplay.
dynamicGlyphFactory = DynamicDisplay.getDynamicGlyphFactory();
//Cast the DynamicDisplay into DynamicSymbolProperties.
dynamicSymbolProps = (IDynamicSymbolProperties)DynamicDisplay;
� � �
//Do other initializations here.
//Call a method to create your glyph.
CreateMarkerGlyph();
bOnce = false;
}
Implementing the CreateMarkerGlyph method
The following goes through the required steps to implement the createMarkerGlyph() method.
- At the bottom of your code, add a new createMarkerGlyph() private method. See the following:
private void createMarkerGlyph(){}
- Set the color that will be used as a background by the DynamicGlyph. See the following:
//Set the background color to white.
IRgbColor color = new RgbColor();
color.setRed(255);
color.setGreen(255);
color.setBlue(255);
- Create the marker symbol. In this example, create a character marker symbol. For convenience, use the ToStdFont() method, which converts a .NET font into stdole.IFontDisp. See the following:
ICharacterMarkerSymbol charMarkerSymbol = new CharacterMarkerSymbol();
StdFont font = new StdFont();
font.setName("ESRI Default Marker");
charMarkerSymbol.setFont(font);
- Set the font's character index, size, and background color. See the following:
charMarkerSymbol.setCharacterIndex(96);
charMarkerSymbol.setSize(12.0);
charMarkerSymbol.setColor((IColor)color);
- Use the previously cached DynamicGlyphFactory to generate the glyph. See the following:
markerGlyph = dynamicGlyphFactory.createDynamicGlyph((ISymbol)charMarkerSymbol);
The glyph is now created and you can use it to draw the marker on the map.
Drawing the marker element
Before drawing the element, set the dynamic symbol properties. This includes setting the heading, alignment, color, scale, and the glyph.
- Set the heading of the dynamic symbol. See the following:
dynamicSymbolProps.setHeading(esriDynamicSymbolType.esriDSymbolMarker, (float)
heading);
- Set the rotation alignment of the dynamic symbol. The symbol's rotation can be aligned in three positions: with the actual orientation of the element (set by the heading), with the window, or with the north direction (the element will always face north). See the following:
//Set the symbol's alignment so that it will align with the symbol's heading.
dynamicSymbolProps.setRotationAlignment(esriDynamicSymbolType.esriDSymbolMarker,
esriDynamicSymbolRotationAlignment.esriDSRAScreen);
- Scale the symbol. Scaling refers to the scale relative to the original size of the active symbol. When scaling, you can use different scaling for x- and y-axis. See the following:
dynamicSymbolProps.setScale(esriDynamicSymbolType.esriDSymbolMarker, 1.1f, 1.1f);
- Assign color to the symbol. See the following:
dynamicSymbolProps.setColor(esriDynamicSymbolType.esriDSymbolMarker, 0.0f, 1.0f,
0.6f, 1.0f); // GREEN
- Set the dynamic glyph. See the following:
dynamicSymbolProps.setDynamicGlyph(esriDynamicSymbolType.esriDSymbolMarker,
markerGlyph);
- Draw the marker symbol. You need a point geometry to specify where the marker will be drawn. See the following:
dynamicDisplay.drawMarker(point);
See Also:
Dynamic Drawing APIsSample :Dynamic Layer WalkThrough
How to draw a bitmap element using OpenGL
Development licensing | Deployment licensing |
---|---|
Engine Developer Kit | Engine |
ArcGIS for Desktop Basic | |
ArcGIS for Desktop Standard | |
ArcGIS for Desktop Advanced |