Click or drag to resize
Code Example: Camera_Properties

Shows adjusting the Camera Properties of a SceneView to view different perspectives of data on the Earth.

Code Example
Camera Properties

This section contains selected code files from a Visual Studio project that emphasize specific ArcGIS Runtime SDK (Windows Desktop) features. For example: some code examples may accomplish the bulk of the work as a configuration property in the .xaml file and hence only the .xaml file will be shown in detail below. In other code examples, the .xaml is used to define the configuration of graphical elements for the application but the application logic is performed in the code behind, hence you may see both the .xaml and .cs/.vb files shown in detail below.

XAML
<Window x:Class="Camera_Properties.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:esri="http://schemas.esri.com/arcgis/runtime/2013" 
        Title="MainWindow" Height="600" Width="800">
    <Grid>
        <StackPanel Orientation="Vertical" Margin="10">

            <!-- Slider for the Heading (in Degrees) of the Camera. -->
            <StackPanel Orientation="Horizontal">
                <Slider x:Name="Slider_Heading" Width="675" ValueChanged="Slider_ValueChanged" AutoToolTipPlacement="BottomRight" />
                <Label Content="Heading: "/>
                <TextBlock x:Name="Heading_Value" VerticalAlignment="Center"/>
            </StackPanel>

            <!-- Slider for the Pitch (in Degrees) of the Camera. -->
            <StackPanel Orientation="Horizontal">
                <Slider x:Name="Slider_Pitch" Width="675" ValueChanged="Slider_ValueChanged" AutoToolTipPlacement="BottomRight" />
                <Label Content="Pitch: " />
                <TextBlock x:Name="Pitch_Value" VerticalAlignment="Center"/>
            </StackPanel>

            <!-- Slider for the Z value (aka. Elevation in Meters) of the Camera's Location. -->
            <StackPanel Orientation="Horizontal">
                <Slider x:Name="Slider_Z" Width="675" ValueChanged="Slider_ValueChanged" AutoToolTipPlacement="BottomRight" />
                <Label Content="Z: " />
                <TextBlock x:Name="Z_Value" VerticalAlignment="Center"/>
            </StackPanel>

            <!-- Slider for the X value (aka. Longitude in Decimal Degrees) of the Camera's Location. -->
            <StackPanel Orientation="Horizontal">
                <Slider x:Name="Slider_X" Width="675" ValueChanged="Slider_ValueChanged" AutoToolTipPlacement="BottomRight" AutoToolTipPrecision="2" />
                <Label Content="X: " />
                <TextBlock x:Name="X_Value" VerticalAlignment="Center"/>
            </StackPanel>

            <!-- Slider for the Y value (aka. Latitude in Decimal Degrees) of the Camera's Location. -->
            <StackPanel Orientation="Horizontal">
                <Slider x:Name="Slider_Y" Width="675" ValueChanged="Slider_ValueChanged" AutoToolTipPlacement="BottomRight" AutoToolTipPrecision="2" />
                <Label Content="Y: " />
                <TextBlock x:Name="Y_Value" VerticalAlignment="Center"/>
            </StackPanel>

            <!-- Add a SceneView Control to display 3D data.-->
            <esri:SceneView x:Name="SceneView1" Width="775" Height="410" />

        </StackPanel>
    </Grid>
</Window>

SPECIAL NOTE: The XAML displayed above comes from a C# project. If you are a VB.NET developer, you will need to modify the text for the x:Class namespace from "Camera_Properties.MainWindow" to be just "MainWindow".

// INSTRUCTIONS:
// When the application loads move the various sliders around to see how adjusting the Properties of the Camera
// via the Heading, Pitch, and Location (X,Y,Z) impact what can be viewed in the SceneView.

namespace Camera_Properties
{
    public partial class MainWindow : System.Windows.Window
    {
        public MainWindow()
        {
            InitializeComponent();

            // Set the initial properties, Slider for the Heading (in Degrees) of the Camera. 
            Slider_Heading.Minimum = 0;
            Slider_Heading.Maximum = 360;
            Slider_Heading.TickFrequency = 1;

            // Set the initial properties, Slider for the Pitch (in Degrees) of the Camera.
            Slider_Pitch.Minimum = 0;
            Slider_Pitch.Maximum = 180;
            Slider_Pitch.TickFrequency = 1;

            // Set the initial properties, Slider for the Z value (aka. Elevation in Meters) of the Camera's Location. 
            Slider_Z.Minimum = 0;
            Slider_Z.Maximum = 5000000;
            Slider_Z.TickFrequency = 1;
            Slider_Z.Value = 2500000;

            // Set the initial properties, Slider for the X value (aka. Longitude in Decimal Degrees) of the Camera's Location.
            Slider_X.Minimum = 0;
            Slider_X.Maximum = 120;
            Slider_X.TickFrequency = 0.01;
            Slider_X.Value = 83.61;

            // Set the initial properties, Slider for the Y value (aka. Latitude in Decimal Degrees) of the Camera's Location. 
            Slider_Y.Minimum = 0;
            Slider_Y.Maximum = 75;
            Slider_Y.TickFrequency = 0.01;
            Slider_Y.Value = 27.74;

            // Create a new ArcGISDynamicMapServiceLayer using Esri's 'World Light Gray Base' MapService.
            Esri.ArcGISRuntime.Layers.ArcGISDynamicMapServiceLayer myArcGISDynamicMapServiceLayer = new Esri.ArcGISRuntime.Layers.ArcGISDynamicMapServiceLayer();
            myArcGISDynamicMapServiceLayer.ServiceUri = "http://services.arcgisonline.com/ArcGIS/rest/services/Canvas/World_Light_Gray_Base/MapServer";

            // Add the ArcGISDynamicMapServiceLayer to the LayerCollection of the Scene in the SceneView.
            SceneView1.Scene.Layers.Add(myArcGISDynamicMapServiceLayer);
        }

        private void Slider_ValueChanged(object sender, System.Windows.RoutedPropertyChangedEventArgs<double> e)
        {
            // This sub-routine will execute when the application first loads to establish the Camera's initial position/perspective and will execute 
            // each time the user adjusts one of the 5 sliders.

            // Define the Location (aka. 3D MapPoint) for the Camera.
            Esri.ArcGISRuntime.Geometry.MapPoint myLocation = new Esri.ArcGISRuntime.Geometry.MapPoint(Slider_X.Value, Slider_Y.Value, Slider_Z.Value, Esri.ArcGISRuntime.Geometry.SpatialReferences.Wgs84);

            // Define the Heading for the Camera.
            double myHeading = Slider_Heading.Value;

            // Define the Pitch for the Camera.
            double myPitch = Slider_Pitch.Value;

            // Define the Camera using Location, Heading, and Pitch.
            Esri.ArcGISRuntime.Controls.Camera myCamera = new Esri.ArcGISRuntime.Controls.Camera(myLocation, myHeading, myPitch);

            // Apply the Camera's position/perspective to the SceneView. 
            SceneView1.SetView(myCamera);

            // Display the various Camera Properties:
            Heading_Value.Text = myCamera.Heading.ToString();
            Pitch_Value.Text = myCamera.Pitch.ToString();
            X_Value.Text = myCamera.Location.X.ToString();
            Y_Value.Text = myCamera.Location.Y.ToString();
            Z_Value.Text = myCamera.Location.Z.ToString();
        }
    }
}