I'm trying to find out how to open Viewer window (menu Windows->Viewer in ArcMap) programmatically and zoom it to a specific location. This is how I can open it:
IDataWindowFactory dwf = new MapViewerWindowFactoryClass();
IDataWindow dw = dwf.Create(mArcMap); // typeof mArcMap is IApplication
and to show it:
dw.Show(true);
but I can't find a way to set the initial extent when opening the viewer window or at least how to change it after it is loaded.
Problem solved by using IMapInsetWindow interface.
IDataWindow2 dw = this.createDataWindow(new MapViewerWindowFactoryClass());
IMapInsetWindow mapInset = dw as IMapInsetWindow;
mapInset.MapInset.VisibleBounds = extent;
dw.Show(true);
1 Answer 1
Below is some code in VBA that shows how to set the extent of the viewer window to the current map. The key interface is IMapInsetWindow which gives you access to the IMapInset2 and it's read/write properties.
Public Sub updateMapView()
' Get map document
Dim pMXDoc As IMxDocument
Set pMXDoc = ThisDocument
' Get Map
Dim pMap As IMap
Set pMap = pMXDoc.FocusMap
' Get the active view of the map
Dim pActiveView As IActiveView
Set pActiveView = pMap
' Get extent of map
Dim pEnvelope As IEnvelope
Set pEnvelope = pActiveView.Extent
' Get Application
Dim pApp As IApplication
Set pApp = Application
' Create Factory
Dim pDataWindowFactory As IDataWindowFactory
Set pDataWindowFactory = New MapViewerWindowFactory
' Create MapViewer Window and open it
Dim pDataWindow As IDataWindow2
Set pDataWindow = pDataWindowFactory.Create(pApp)
pDataWindow.Show True
' Cast DataWindow into MapInsetWindow
Dim pMapInsetWindow As IMapInsetWindow
Set pMapInsetWindow = pDataWindow
' Set the extent of the InsetWindow to the current map Extent
pMapInsetWindow.MapInset.VisibleBounds = pEnvelope
End Sub
-
Thanks, thats great! I actually saw a similar answer but thought that IMapInsetWindow class is used only for managing the Magnifier window and not for the Viewer window, which I want to use.Bogdan Hristozov– Bogdan Hristozov2015年07月29日 20:50:39 +00:00Commented Jul 29, 2015 at 20:50