More

Tracking Map Events in ArcObjects Dockable-Window Addin?


I'm building an Addin for ArcGIS 10.2 with c#.

It is a dockable Window, that will host some controls for our custom export solution.

I want to listen to Map-Move events of the main map (IActiveView), to update the display of the current bounding box coordinates within the dockable window.

My problem is, I can't find a good way to listen to the mapevents. The only way I found is by creating a new IMapControl->IMapControlEvents2 object and listen to the OnExtentUpdated Event.

Is there something that I can use by casting from IActiveView or do I have to create a new IMapControl object?


MapControl is an engine component to create your own window to display map contents. I've looked before and never found a way to get a reference to the ArcMap MapControl. ArcMap may not even use a MapControl for its display, it may use some other internal class.

Two options:

1)

var ave = ActiveView as IActiveViewEvents; ave.AfterDraw += onAfterDraw;

protected static void onAfterDraw( IDisplay DISPLAY, esriViewDrawPhase PHASE ) { if( PHASE != esriViewDrawPhase.esriViewForeground ) return;… [update coordinates] }

You will get extra messages that aren't related to the extents changing, but if you're just using the event to update displayed coord it might be acceptable.

2) A number of classes implement ITransformEvents, but only 2 as events: TransformEventsListener (C++ helper coclass, not applicable here), and DisplayTransformation.

var te = ActiveView.ScreenDisplay.DisplayTransformation as ITransformEvents_Event te.VisibleBoundsUpdated += onVsibleBoundsUpdated;

protected static void onVsibleBoundsUpdated( IDisplayTransformation TRANSFORMATIONmay , bool SIZECHANGED ) {… [update coordinates] }

I would use the onAfterDraw otherwise you may have to listen to several ITransformEvents e.g. onAfterDraw fired for pan, zoom, map rotate; onVisibleBoundsUpdated fired for pan, zoom, but NOT map rotate.

FWIW, when it's fired, onVisibleBoundsUpdated is fired before onAfterDraw.

You may also have to remove/add your handler as the active view changes. So if your using doc.ActiveView you should unhook/rehook the av events when it changes, likewise if you are using FocusMap.