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);
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
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. – Bogdan Hristozov Jul 29 '15 at 20:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.