ArcGIS Pro 2.9 API Reference Guide
Camera Class
Members  Example 

ArcGIS.Desktop.Mapping Namespace : Camera Class
Represents an object that defines the displayed content of a view via its viewing location and viewing direction.
Object Model
Camera ClassSpatialReference Class
Syntax
public class Camera 
Public Class Camera 
Remarks

Both 2D and 3D views define and manage what is being displayed using a camera object. You can get the current camera for the view using the MapView.Camera property.

In 2D, the camera defines its viewing location using X and Y. The values are in the same units as those defined by the camera's SpatialReference. This will be the center point of the 2D view's extent. The viewing direction, or rotation, of the map is defined using the camera's Heading property. The camera's Scale property then defines how far the view is zoomed in or out, and the 2D view will be able to display content for that area. You can also get the extent from the view using the MapView.Extent property.

In 3D, the camera defines its viewing location using X, Y and Z. As with 2D, the values are stored in the same units as those defined by the camera's SpatialReference, with the additional possibility that XY units and Z units may be different. This will be the central position for the 3D view, as though a helicopter was hovering in that location. The viewing direction is defined by a combination of the Heading, Pitch, and Roll properties, which will rotate, tilt, and roll how the camera looks at the content around it, and the 3D view will be able to display content for the defined frustum.

Example
Create a dock pane showing the camera properties for the active map view.
<!--

   Copyright 2018 Esri

   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

   See the License for the specific language governing permissions and
   limitations under the License.

-->
<UserControl x:Class="Examples.CameraDockPane"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"                                             
             mc:Ignorable="d" 
             d:DesignHeight="300" d:DesignWidth="300">
    <UserControl.Resources>
        <Style TargetType="TextBlock">
            <Setter Property="Margin" Value="0,0,4,0"/>
            <Setter Property="Grid.Column" Value="0"/>
            <Setter Property="VerticalAlignment" Value="Center"/>
        </Style>
        <Style TargetType="TextBox">
            <Setter Property="Margin" Value="0,2"/>
            <Setter Property="Height" Value="22"/>
            <Setter Property="Grid.Column" Value="1"/>
            <Setter Property="VerticalAlignment" Value="Center"/>
            <Setter Property="TextAlignment" Value="Right"/>
            <Setter Property="Padding" Value="2"/>
        </Style>
        <Style TargetType="{x:Type Button}">
            <Setter Property="VerticalAlignment" Value="Center"/>
            <Setter Property="Background" Value="Transparent"/>
            <Setter Property="BorderBrush" Value="Transparent"/>
            <Setter Property="Width" Value="20"/>
            <Setter Property="Height" Value="20"/>
            <Style.Triggers>
                <Trigger Property="IsEnabled" Value="false">
                    <Setter Property="Opacity" Value="0.5"/>
                    <Setter Property="BorderBrush" Value="Transparent"/>
                    <Setter Property="Background" Value="Transparent"/>
                </Trigger>
            </Style.Triggers>
        </Style>
    </UserControl.Resources>
      <Grid Margin="4">
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="Auto"/>
            <ColumnDefinition Width="*"/>
        </Grid.ColumnDefinitions>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="Auto"/>
        </Grid.RowDefinitions>
        <TextBlock Text="X:" Grid.Row="0"/>
        <TextBlock Text="Y:" Grid.Row="1"/>
        <TextBlock Text="Z:" Grid.Row="2"/>
        <TextBlock Text="Scale:" Grid.Row="3"/>
        <TextBlock Text="Pitch:" Grid.Row="4"/>
        <TextBlock Text="Roll:" Grid.Row="5"/>
        <TextBlock Text="Heading:" Grid.Row="6"/>
        <TextBox Text="{Binding Path=Camera.X, StringFormat=N3, Mode=TwoWay}" Grid.Row="0"/>
        <TextBox Text="{Binding Path=Camera.Y, StringFormat=N3, Mode=TwoWay}" Grid.Row="1"/>
        <TextBox Text="{Binding Path=Camera.Z, StringFormat=N3, Mode=TwoWay}" Grid.Row="2"/>
        <TextBox Text="{Binding Path=Camera.Scale, StringFormat=N3, Mode=TwoWay}" Grid.Row="3"/>
        <TextBox Text="{Binding Path=Camera.Pitch, StringFormat=N3, Mode=TwoWay}" Grid.Row="4"/>
        <TextBox Text="{Binding Path=Camera.Roll, StringFormat=N3, Mode=TwoWay}" Grid.Row="5"/>
        <TextBox Text="{Binding Path=Camera.Heading, StringFormat=N3, Mode=TwoWay}" Grid.Row="6"/>
        <StackPanel Orientation="Horizontal" HorizontalAlignment="Right" Grid.Row="7" Grid.Column="1">
            <Button Command="{Binding Path=ZoomToCmd}" Margin="0,0,2,0">
                <Button.Content>
                    <Image HorizontalAlignment="Center" VerticalAlignment="Center" Source="pack://application:,,,/ArcGIS.Desktop.Resources;component/Images/ZoomGeneric_B_16.png"/>
                </Button.Content>
            </Button>
            <Button Command="{Binding Path=PanToCmd}">
                <Button.Content>
                    <Image HorizontalAlignment="Center" VerticalAlignment="Center" Source="pack://application:,,,/ArcGIS.Desktop.Resources;component/Images/PanTool_B_16.png"/>
                </Button.Content>
            </Button>
        </StackPanel>
    </Grid>
</UserControl>
/*

   Copyright 2018 Esri

   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

   See the License for the specific language governing permissions and
   limitations under the License.

*/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ArcGIS.Desktop.Framework;
using ArcGIS.Desktop.Framework.Contracts;
using ArcGIS.Desktop.Mapping;
using ArcGIS.Desktop.Mapping.Events;
using System.Windows.Input;

namespace Examples
{
  /// <summary>
  /// ViewModel for the Camera DockPane.
  /// </summary>
  internal class CameraDockPaneViewModel : DockPane
  {
    /// <summary>
    /// Subscribe to the MapViewCameraChangedEvent and ActiveMapViewChangedEvent when the DockPane is created.
    /// </summary>
    public CameraDockPaneViewModel() 
    {
      MapViewCameraChangedEvent.Subscribe(OnCameraChanged);
      ActiveMapViewChangedEvent.Subscribe(OnActiveMapViewChanged);

      if (MapView.Active != null)
        Camera = MapView.Active.Camera;
    }

    /// <summary>
    /// Unsubscribe from the MapViewCameraChangedEvent and ActiveMapViewChangedEvent when the DockPane is destroyed.
    /// </summary>
    ~CameraDockPaneViewModel()
    {
      if (_zoomToCmd != null)
        _zoomToCmd.Disconnect();

      if (_panToCmd != null)
        _panToCmd.Disconnect();

      ActiveMapViewChangedEvent.Unsubscribe(OnActiveMapViewChanged);
      MapViewCameraChangedEvent.Unsubscribe(OnCameraChanged);
    }

    /// <summary>
    /// Bindable property for the camera in the active map view.
    /// </summary>
    private Camera _camera;
    public Camera Camera
    {
      get { return _camera; }
      set
      {
        SetProperty(ref _camera, value, () => Camera);
      }
    }

    /// <summary>
    /// Bindable command for the Pan To button.
    /// </summary>
    private RelayCommand _panToCmd;
    public ICommand PanToCmd
    {
      get 
      {
        if (_panToCmd == null)
        {
          _panToCmd = new RelayCommand(() => MapView.Active.PanToAsync(Camera, TimeSpan.FromSeconds(1.5)), () => { return MapView.Active != null; }); 
        }
        return _panToCmd;
      }
    }


    /// <summary>
    /// Bindable command for the Zoom To button.
    /// </summary>
    private RelayCommand _zoomToCmd;
    public ICommand ZoomToCmd
    {
      get 
      {
        if (_zoomToCmd == null)
        {
          _zoomToCmd = new RelayCommand(() => MapView.Active.ZoomToAsync(Camera, TimeSpan.FromSeconds(1.5)), () => { return MapView.Active != null; }); 
        }
        return _zoomToCmd;
      }
    }

    /// <summary>
    /// Event delegate for the MapViewCameraChangedEvent
    /// </summary>
    private void OnCameraChanged(MapViewCameraChangedEventArgs obj)
    {
      if (obj.MapView == MapView.Active)
        Camera = obj.CurrentCamera;
    }

    /// <summary>
    /// Event delegate for the ActiveMapViewChangedEvent
    /// </summary>
    private void OnActiveMapViewChanged(ActiveMapViewChangedEventArgs obj)
    {
      if (obj.IncomingView == null)
      {
        Camera = null;
        return;
      }
        
      Camera = obj.IncomingView.Camera;
    }
  }
}
Inheritance Hierarchy

System.Object
   ArcGIS.Desktop.Mapping.Camera

Requirements

Target Platforms: Windows 11, Windows 10, Windows 8.1

See Also

Reference

Camera Members
ArcGIS.Desktop.Mapping Namespace