ArcObjects Library Reference

Zoom to Globe Layer Snippet

Zooms to the specified layer in the globe at a specific index number.

[C#]

///<summary>Zooms to the specified layer in the globe at a specific index number.</summary>
/// 
///<param name="globe">An IGlobe interface</param>
///<param name="layerIndex">A System.Int32 that is the layer index number in the globe (zero based). Example: 0</param>
///  
///<remarks></remarks>
public void ZoomToGlobeLayer(ESRI.ArcGIS.GlobeCore.IGlobe globe, System.Int32 layerIndex)
{
  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 = (ESRI.ArcGIS.Analyst3D.IScene)globe; // Explicit Cast
  ESRI.ArcGIS.Carto.ILayer layer = scene.get_Layer(layerIndex);
  ESRI.ArcGIS.Geometry.IEnvelope envelope = layer.AreaOfInterest.Envelope;
  globeCamera.SetToZoomToExtents(envelope, globe, sceneViewer);
}
[Visual Basic .NET]

'''<summary>Zooms to the specified layer in the globe at a specific index number.</summary>
''' 
'''<param name="globe">An IGlobe interface</param>
'''<param name="layerIndex">A System.Int32 that is the layer index number in the globe (zero based). Example: 0</param>
'''  
'''<remarks></remarks>
Public Sub ZoomToGlobeLayer(ByVal globe As ESRI.ArcGIS.GlobeCore.IGlobe, ByVal layerIndex As System.Int32)

  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) ' Explicit Cast
  Dim scene As ESRI.ArcGIS.Analyst3D.IScene = CType(globe, ESRI.ArcGIS.Analyst3D.IScene) ' Explicit Cast

  Dim layer As ESRI.ArcGIS.Carto.ILayer = scene.Layer(layerIndex)

  Dim envelope As ESRI.ArcGIS.Geometry.IEnvelope = layer.AreaOfInterest.Envelope
  globeCamera.SetToZoomToExtents(envelope, globe, sceneViewer)

End Sub


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