Creating dynamic glyphs
Creation of dynamic glyphs must take place inside one of the dynamic drawing methods; that is, 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 properties from the DynamicDisplay
Keep 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 code example:
if (m_bOnce)
{
//Get the DynamicGlyphFactory from the DynamicDisplay.
m_dynamicGlyphFactory = DynamicDisplay.DynamicGlyphFactory;
//Cast the DynamicDisplay into DynamicSymbolProperties.
m_dynamicSymbolProps = DynamicDisplay as IDynamicSymbolProperties;
� � �
//Do other initializations here.
//Call a method to create your glyph.
CreateMarkerGlyph();
m_bOnce = false;
}
[VB.NET]
If m_bOnce Then
'Get the DynamicGlyphFactory from the DynamicDisplay.
m_dynamicGlyphFactory = DynamicDisplay.DynamicGlyphFactory
'Cast the DynamicDisplay into DynamicSymbolProperties.
m_dynamicSymbolProps = TryCast(DynamicDisplay, IDynamicSymbolProperties)
…
/ / Do other initializations here.
/ / Call a method To create your glyph.
CreateMarkerGlyph()
m_bOnce = False
End If
Implementing CreateMarkerGlyph
Do the following required steps to implement the CreateMarkerGlyph() method.
- At the bottom of your code, add a new CreateMarkerGlyph() private method. See the following code example:
private void CreateMarkerGlyph(){}
[VB.NET]
Private Sub CreateMarkerGlyph()
End Sub
- Set the color that will be used as a background by the DynamicGlyph. See the following code example:
//Set the background color to white.
IRgbColor color = new RgbColorClass();
color.Red = 255;
color.Green = 255;
color.Blue = 255;
[VB.NET]
'Set the background color to white.
Dim color As IRgbColor = New RgbColorClass()
color.Red = 255
color.Green = 255
color.Blue = 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 code example:
ICharacterMarkerSymbol charMarkerSymbol = new CharacterMarkerSymbolClass();
charMarkerSymbol.Font = ESRI.ArcGIS.ADF.Converter.ToStdFont(new Font(new FontFamily(
"ESRI Default Marker")));
[VB.NET]
charMarkersymbol = New CharacterMarkerSymbolClass()
charMarkersymbol.Font = ESRI.ArcGIS.ADF.Converter.ToStdFont(New Font(New FontFamily("ESRI Default Marker"), 10.0F, FontStyle.Regular))
- Set the font's character index, size, and background color. See the following code example:
charMarkerSymbol.CharacterIndex = 96;
charMarkerSymbol.Size = 12.0;
charMarkerSymbol.Color = (IColor)color;
[VB.NET]
charMarkerSymbol.CharacterIndex = 96
charMarkerSymbol.Size = 40
charMarkerSymbol.Color = TryCast(color, IColor)
- Use the previously cached DynamicGlyphFactory to generate the glyph. See the following code example:
m_markerGlyph = m_dynamicGlyphFactory.CreateDynamicGlyph(charMarkerSymbol as ISymbol)
;
[VB.NET]
m_markerGlyph = pDynamicGlyphFactory.CreateDynamicGlyph(TryCast(charMarkerSymbol, ISymbol))
- The glyph is 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 code example:
m_dynamicSymbolProps.set_Heading(esriDynamicSymbolType.esriDSymbolMarker, (float)
heading);
[VB.NET]
m_dynamicSymbolProps.Heading(esriDynamicSymbolType.esriDSymbolMarker) = CSng(heading)
- Set the rotation alignment of the dynamic symbol. The symbol's rotation can be aligned in the following positions:
- With the actual orientation of the element (set by the heading)
- With the window
- With the north direction (the element will always face north).
See the following code example:
//Set the symbol's alignment to align with the symbol's heading.
m_dynamicSymbolProps.set_RotationAlignment(esriDynamicSymbolType.esriDSymbolMarker,
esriDynamicSymbolRotationAlignment.esriDSRAHeading);
[VB.NET]
'Set the symbol's alignment to align with the symbol's heading.
m_dynamicSymbolProps.RotationAlignment(esriDynamicSymbolType.esriDSymbolMarker) = esriDynamicSymbolRotationAlignment.esriDSRAHeading
- 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 the x- and y-axis. See the following code example:
m_dynamicSymbolProps.SetScale(esriDynamicSymbolType.esriDSymbolMarker, 1.1f, 1.1f);
[VB.NET]
m_dynamicSymbolProps.SetScale(esriDynamicSymbolType.esriDSymbolMarker, 1.1F, 1.1F)
- Assign color to the symbol. See the following code example:
m_dynamicSymbolProps.SetColor(esriDynamicSymbolType.esriDSymbolMarker, 0.0f, 1.0f,
0.6f, 1.0f); // GREEN
[VB.NET]
m_dynamicSymbolProps.SetColor(esriDynamicSymbolType.esriDSymbolMarker, 0.0F, 1.0F, 0.6F, 1.0F) ' GREEN
- Set the dynamic glyph. See the following code example:
m_dynamicSymbolProps.set_DynamicGlyph(esriDynamicSymbolType.esriDSymbolMarker,
m_markerGlyph);
[VB.NET]
m_dynamicSymbolProps.DynamicGlyph(esriDynamicSymbolType.esriDSymbolMarker) = m_markerGlyph
- Draw the marker symbol. You need a point geometry to specify where the marker will be drawn. See the following code example:
DynamicDisplay.DrawMarker(m_point);
[VB.NET]
DynamicDisplay.DrawMarker(m_point)
See Also:
Dynamic displayMaximizing performance in dynamic display
Sample: Dynamic display layer
Sample: Dynamic display—tracking dynamic object
Development licensing | Deployment licensing |
---|---|
Engine Developer Kit | Engine |
ArcGIS for Desktop Basic | |
ArcGIS for Desktop Standard | |
ArcGIS for Desktop Advanced |