4

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.

enter image description here


Problem solved by using IMapInsetWindow interface.

IDataWindow2 dw = this.createDataWindow(new MapViewerWindowFactoryClass());
IMapInsetWindow mapInset = dw as IMapInsetWindow;
mapInset.MapInset.VisibleBounds = extent;
dw.Show(true);
PolyGeo
65.5k29 gold badges115 silver badges350 bronze badges
asked Jul 29, 2015 at 7:47

1 Answer 1

3

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
answered Jul 29, 2015 at 13:37
1
  • 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. Commented Jul 29, 2015 at 20:50

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.