Dynamic Map Events

This article describes the dynamic map events that are fired when a map is in dynamic mode. It also discusses the sequence of these events under different scenarios.

In this topic

About Dynamic Map Events

The Dynamic Map is an active Display, therefore the dynamic display changes in events like - dirty dynamic layer, map navigation that changes the visible bounds and/or, map refresh. The following Dynamic Map Events occur when the state of the dynamic map changes.

Listening to Dynamic Map Events


You can listen to dynamic Map events by attaching a listener to the dynamic map using the method map.addIDynamicMapEventsListener() and the listener can be removed using the method map.removeIDynamicMapEventsListener().


The following code snippet draws a simple marker at a random point by listening to dynamic map events. 
// The following class variables are created for the code snippet below

private boolean bOnce = true;
private int drawPhase;
private IDynamicDisplay dynamicDisplay;
private IDynamicGlyphFactory dynamicGlyphFactory;
private IDynamicSymbolProperties2 dynamicSymbolProps;
private IDynamicGlyph markerGlyph;
private IDisplay display;
private Map map;

//obtain the current map and add the listener to listen to events

//Check is the map is in dynamic mode
if (!map.isDynamicMapEnabled())
    return ;
    map.addIDynamicMapEventsListener(new IDynamicMapEventsAdapter(){

        public void dynamicMapStarted(IDynamicMapEventsDynamicMapStartedEvent event)
            throws IOException, AutomationException{
            System.out.println("Dynamic Map Started"); 
            /*The IDynamicMapEvents.afterDynamicDraw() event is fired
             * only when dynamic rendering takes place. 
             *Therefore to force this event in every draw cycle,
             * the map is refreshed

        public void beforeDynamicDraw(IDynamicMapEventsBeforeDynamicDrawEvent event)
            throws IOException, AutomationException{
            System.out.println("Before Dynamic Draw Event"); 

        public void afterDynamicDraw(IDynamicMapEventsAfterDynamicDrawEvent event)
            throws IOException, AutomationException{

            //Draw a simple dynamic symbol at a random location in esriDMDPDynamicLayers phase

            if (event.getDynamicMapDrawPhase() ==
                dynamicDisplay = event.getDynamicDisplay(); display =
                //Create a simple marker from ICharacterMarkerSymbol
                if (bOnce){

                    dynamicGlyphFactory = dynamicDisplay.getDynamicGlyphFactory();
                        dynamicSymbolProps = (IDynamicSymbolProperties2)

                    //Create a dynamic glyph from CharacterMarker symbol
                    ICharacterMarkerSymbol markerSymbol = new CharacterMarkerSymbol()
                        ; markerSymbol.setCharacterIndex(72); markerSymbol.setSize
                        (25.0); IColor color = new RgbColor(); color.setRGB(0xFFFFFF)
                        ; markerSymbol.setColor(color); markerGlyph =
                        ; bOnce = false;  
                        // Create glyphs only once, since they are expensive

                // Set the properties of the dynamic Symbol
                    1.0f, 0.0f, 0.0f, 1.0f); dynamicSymbolProps.setDynamicGlyphByRef
                    (esriDynamicSymbolType.esriDSymbolMarker, markerGlyph); 

                //Select a random point in visible bounds
                IEnvelopeGEN visibleExtent = (IEnvelopeGEN)
                    display.getDisplayTransformation().getVisibleBounds(); Random r 
                    = new Random(); double X = visibleExtent.getXMin() +
                    r.nextDouble() * visibleExtent.getWidth(); double Y =
                    visibleExtent.getYMin() + r.nextDouble() *
                    visibleExtent.getHeight(); Point point = new Point();
                    point.putCoords(X, Y); 

                //draw the marker on dynamic display

        public void dynamicMapFinished(IDynamicMapEventsDynamicMapFinishedEvent
            event)throws IOException, AutomationException{
            System.out.println("Dynamic Map Finished"); 

Understanding Dynamic Map Events

The difference between the BeforeDynamicDraw\AfterDynamicDraw and the DynamicMapStarted\DynamicMapFinished events, is that the BeforeDynamicDraw\AfterDynamicDraw Events will get fired only when the Display (Dynamic Map) needs to be redrawn, while the DynamicMapStarted\DynamicMapFinished events will get fired on every Dynamic Map heart beat (while the Dynamic Map is Enabled), even when the display is not redrawn. The following sequences represents the events fired at different scenarios.
Scenario 1 : The DynamicMapStarted and DynamicMapFinished events are fired in every draw cycle, when the dynamic Map is enabled. See figure below:
Scenario 2: The BeforeDynamicDraw and AfterDynamicDraw events in esriDMDPDynamicLayers phase are fired, when the dynamic map is enabled and whenever the dynamic layers are rendered. For example, when a dynamic layer is dirty. See figure below:
Scenario 3: The BeforeDynamicDraw and AfterDynamicDraw events are fired in esriDMDPLayers phase, when the dynamic map is enabled and when the underlying static layers(of the base map) are rendered as a result of map navigation(pan/zoom,roam), map refresh etc. See figure below:
The dynamic layers are also rendered whenever the static layers(of the base map) are rendered irrespective of its dirty property.
This article explains the dynamic map events and how they could be used in a dynamic mode to render dynamic content. It also details the sequence of events that are fired under different scenarios such as, map navigation, map refresh or when a dynamic layer is dirty. 

See Also:

Rendering Dynamic Content
Dynamic Drawing APIs
Sample: Heads up display using OpenGL

Development licensingDeployment licensing
Engine Developer KitEngine