ArcGIS Pro 3.7 API Reference Guide
ArcGIS.Desktop.Mapping Namespace / MapView Class / Camera Property
Example

In This Topic
    Camera Property (MapView)
    In This Topic
    Gets the current Camera of the view.
    Syntax
    Public ReadOnly Property Camera As Camera
    public Camera Camera {get;}
    Remarks
    Use this in combination with ZoomTo(Camera,Nullable<TimeSpan>) to get and set the view's camera.
    Example
    SetAutoCameraFixedCenter
    {
      //Note: run within the QueuedTask
      var autoCamera = mapFrame.GetAutoCamera();
      autoCamera.Source = AutoCameraSource.Fixed;
      autoCamera.AutoCameraType = AutoCameraType.Center;
    
      var camera = mapFrame.GetMapView(LayoutView.Active).Camera;
      var center = mapFrame.GetViewCenter();
    
      //var extent = EnvelopeBuilderEx.CreateEnvelope(
      //	400748.62, 800296.4, 1310669.05, 1424520.74, mf.Map.SpatialReference);
      //autoCamera.Extent = extent;
    
      var camera2 = new CIMViewCamera()
      {
        Heading = 0,
        Pitch = -90,
        Roll = 0,
        Scale = 21169571,
        X = 855708,
        Y = 1112409,
        Z = double.NaN
      };
      autoCamera.Camera = camera2;
      var states = mapFrame.Map.GetLayersAsFlattenedList().First(l => l.Name == "State_Polygons");
      autoCamera.IntersectLayerPath = states.URI;
    
      if (mapFrame.ValidateAutoCamera(autoCamera) &&
        !mapFrame.IsMapSeriesMapFrame())
        mapFrame.SetAutoCamera(autoCamera);
    }
    SetAutoCameraFixedCenterAndScale
    {
      //Note: run within the QueuedTask
      var autoCamera = mapFrame.GetAutoCamera();
      autoCamera.Source = AutoCameraSource.Fixed;
      autoCamera.AutoCameraType = AutoCameraType.CenterAndScale;
    
      var camera = mapFrame.GetMapView(LayoutView.Active).Camera;
      var center = mapFrame.GetViewCenter();
    
      //var extent = EnvelopeBuilderEx.CreateEnvelope(
      //	400748.62, 800296.4, 1310669.05, 1424520.74, mf.Map.SpatialReference);
      //autoCamera.Extent = extent;
    
      var camera2 = new CIMViewCamera()
      {
        Heading = 0,
        Pitch = -90,
        Roll = 0,
        Scale = 21169571,
        X = 1310669.0 + ((400748.5 - 1310669.0) / 2.0),
        Y = 800296.4 + ((1424520.74 - 800296.4) / 2.0),
        Z = double.NaN
      };
      autoCamera.Camera = camera2;
      var states = mapFrame.Map.GetLayersAsFlattenedList().First(l => l.Name == "State_Polygons");
      //autoCamera.IntersectLayerPath = states.URI;
      if (mapFrame.ValidateAutoCamera(autoCamera) &&
        !mapFrame.IsMapSeriesMapFrame())
        mapFrame.SetAutoCamera(autoCamera);
    }
    SetAutoCameraFixedScale
    {
      //Note: run within the QueuedTask
    
      var autoCamera = mapFrame.GetAutoCamera();
      autoCamera.Source = AutoCameraSource.Fixed;
      autoCamera.AutoCameraType = AutoCameraType.Scale;
    
      var camera = mapFrame.GetMapView(LayoutView.Active).Camera;
      var center = mapFrame.GetViewCenter();
    
      //var extent = EnvelopeBuilderEx.CreateEnvelope(
      //	400748.62, 800296.4, 1310669.05, 1424520.74, mf.Map.SpatialReference);
      //autoCamera.Extent = extent;
    
      var camera2 = new CIMViewCamera()
      {
        Heading = 0,
        Pitch = -90,
        Roll = 0,
        Scale = 20000571,
        X = 1310669.0 + ((400748.5 - 1310669.0) / 2.0),
        Y = 800296.4 + ((1424520.74 - 800296.4) / 2.0),
        Z = double.NaN
      };
      autoCamera.Camera = camera2;
      var states = mapFrame.Map.GetLayersAsFlattenedList().First(l => l.Name == "State_Polygons");
      //autoCamera.IntersectLayerPath = states.URI;
    
      if (mapFrame.ValidateAutoCamera(autoCamera) &&
        !mapFrame.IsMapSeriesMapFrame())
        mapFrame.SetAutoCamera(autoCamera);
    
    }
    Rotate the map view
    {
      //Get the camera for the view, adjust the heading and zoom to the new camera position.
      camera = mapView.Camera;
      camera.Heading = heading;
      await mapView.ZoomToAsync(camera, TimeSpan.Zero);
      //Or synchronously
      mapView.ZoomTo(camera, TimeSpan.Zero);
    }
    Requirements

    Target Platforms: Windows 11 Home, Pro, Enterprise (64 bit)

    ArcGIS Pro version: 3.0 or higher.
    See Also