This document is archived and information here might be outdated.  Recommended version.


Zoom to 3D Bookmark Snippet (ArcObjects .NET 10.6 SDK)
ArcObjects Library Reference

Zoom to 3D Bookmark Snippet

Zooms to the specified bookmark in the globe.

[C#]
///<summary>Zooms to the specified bookmark in the globe.</summary>
/// 
///<param name="globe">An IGlobe interface</param>
///<param name="bookmarkName">A System.String that is the name of the bookmark, you want to zoom to. Example: "Bookmark 1"</param>
///  
///<remarks></remarks>
public void ZoomTo3DBookmark(ESRI.ArcGIS.GlobeCore.IGlobe globe, System.String bookmarkName)
{
  ESRI.ArcGIS.GlobeCore.IGlobeDisplay globeDisplay=globe.GlobeDisplay;
  ESRI.ArcGIS.Analyst3D.ISceneViewer sceneViewer=globeDisplay.ActiveViewer;
  ESRI.ArcGIS.Analyst3D.ICamera camera=sceneViewer.Camera;
  ESRI.ArcGIS.GlobeCore.IGlobeCamera globeCamera=(ESRI.ArcGIS.GlobeCore.IGlobeCamera)camera; // Explicit Cast
  ESRI.ArcGIS.Analyst3D.IScene scene=globeDisplay.Scene; 
  ESRI.ArcGIS.Analyst3D.ISceneBookmarks sceneBookmarks=(ESRI.ArcGIS.Analyst3D.ISceneBookmarks)scene; // Explicit Cast

  // The next 2 lines of code are different from many other ArcObjects programming techniques in that the IBookmark3D 
  // Interface variable 'bookmark3D' is initialized to a Null value. It is set by reference with the call to the 
  // FindBookmark method; hence the need for the 'out' argument (see MSDN for more information).
  ESRI.ArcGIS.Analyst3D.IBookmark3D bookmark3D; // Initialized to Null
  sceneBookmarks.FindBookmark(bookmarkName, out bookmark3D);

  bookmark3D.Apply(sceneViewer, false, 0);

  // The next 3 lines of code are different from many other ArcObjects programming techniques in that the 
  // double variables of pXT and pYT are initialized to zero by the compiler. These variables are later set to
  // non zero values by a call to the QueryCoords method; hence the need for the 'out' arguments (see 
  // MSDN for more information).
  System.Double pXT; // Initialized To 0 by default
  System.Double pYT; // Initialized To 0 by default
  camera.Target.QueryCoords(out pXT, out pYT);

  System.Double pZT; // Initialized To 0 by default
  pZT=camera.Target.Z;

  if ((pXT * pXT + pYT * pYT + pZT * pZT) < 0.000000000001)
    globeCamera.OrientationMode=ESRI.ArcGIS.GlobeCore.esriGlobeCameraOrientationMode.esriGlobeCameraOrientationGlobal;
  else
    globeCamera.OrientationMode=ESRI.ArcGIS.GlobeCore.esriGlobeCameraOrientationMode.esriGlobeCameraOrientationLocal;

  sceneViewer.Redraw(true);
}
[Visual Basic .NET]
'''<summary>Zooms to the specified bookmark in the globe.</summary>
''' 
'''<param name="globe">An IGlobe interface</param>
'''<param name="bookmarkName">A System.String that is the name of the bookmark, you want to zoom to. Example: "Bookmark 1"</param>
'''  
'''<remarks></remarks>
Public Sub ZoomTo3DBookmark(ByVal globe As ESRI.ArcGIS.GlobeCore.IGlobe, ByVal bookmarkName As System.String)
  
  Dim globeDisplay As ESRI.ArcGIS.GlobeCore.IGlobeDisplay=globe.GlobeDisplay
  Dim sceneViewer As ESRI.ArcGIS.Analyst3D.ISceneViewer=globeDisplay.ActiveViewer
  Dim camera As ESRI.ArcGIS.Analyst3D.ICamera=sceneViewer.Camera
  Dim globeCamera As ESRI.ArcGIS.GlobeCore.IGlobeCamera=CType(camera, ESRI.ArcGIS.GlobeCore.IGlobeCamera) ' Explict Cast
  Dim scene As ESRI.ArcGIS.Analyst3D.IScene=globeDisplay.Scene
  Dim sceneBookmarks As ESRI.ArcGIS.Analyst3D.ISceneBookmarks=CType(scene, ESRI.ArcGIS.Analyst3D.ISceneBookmarks) ' Explicit Cast

  ' The next 2 lines of code are different from many other ArcObjects programming techniques in that the IBookmark3D 
  ' Interface variable 'bookmark3D' is initialized to Nothing. It is set by reference with the call to the 
  ' FindBookmark method.
  Dim bookmark3D As ESRI.ArcGIS.Analyst3D.IBookmark3D=Nothing
  sceneBookmarks.FindBookmark(bookmarkName, bookmark3D)

  bookmark3D.Apply(sceneViewer, False, 0)

  ' The next 3 lines of code are different from many other ArcObjects programming techniques in that the 
  ' double variables of pXT and pYT need to initialized to zero. These variables are later set to
  ' non zero values by a call to the QueryCoords method.
  Dim pXT As System.Double=0
  Dim pYT As System.Double=0
  camera.Target.QueryCoords(pXT, pYT)

  Dim pZT As System.Double
  pZT=camera.Target.Z

  If (pXT * pXT + pYT * pYT + pZT * pZT) < 0.000000000001 Then
   globeCamera.OrientationMode=ESRI.ArcGIS.GlobeCore.esriGlobeCameraOrientationMode.esriGlobeCameraOrientationGlobal
  Else
   globeCamera.OrientationMode=ESRI.ArcGIS.GlobeCore.esriGlobeCameraOrientationMode.esriGlobeCameraOrientationLocal
  End If

  sceneViewer.Redraw(True)

End Sub

Additional Requirements
  • The code in this document requires the following References added to the Visual Studio project:
  • ESRI.ArcGIS.3DAnalyst
  • ESRI.ArcGIS.Geometry
  • ESRI.ArcGIS.GlobeCore