Click or drag to resize

CameraController Class

Base class for all camera controllers.
Inheritance Hierarchy

Namespace:  Esri.ArcGISRuntime.UI
Assembly:  Esri.ArcGISRuntime (in Esri.ArcGISRuntime.dll) Version: 100.6.0.0
Syntax
public abstract class CameraController : INotifyPropertyChanged

The CameraController type exposes the following members.

Events
  NameDescription
Public eventPropertyChanged
Occurs when a property value changes.
Top
Examples

UWP

Example Name: ChooseCameraController

Control the behavior of the camera in a scene.

Code example screen shot.

C#
// Copyright 2019 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 ArcGISRuntime.Samples.Managers;
using Esri.ArcGISRuntime.Geometry;
using Esri.ArcGISRuntime.Mapping;
using Esri.ArcGISRuntime.Symbology;
using Esri.ArcGISRuntime.UI;
using System;
using Windows.UI.Popups;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;

namespace ArcGISRuntime.UWP.Samples.ChooseCameraController
{
    [ArcGISRuntime.Samples.Shared.Attributes.Sample(
        "Choose camera controller",
        "MapView",
        "Control the behavior of the camera in a scene.",
        "Select a radio button to change the camera controller.")]
    [ArcGISRuntime.Samples.Shared.Attributes.OfflineData("681d6f7694644709a7c830ec57a2d72b")]
    public partial class ChooseCameraController
    {
        // Path for elevation data.
        private readonly Uri _elevationUri = new Uri("http://elevation3d.arcgis.com/arcgis/rest/services/WorldElevation3D/Terrain3D/ImageServer");

        // Path for the plane model.
        private readonly Uri _modelUri = new Uri(DataManager.GetDataFolder("681d6f7694644709a7c830ec57a2d72b", "Bristol.dae"));

        // Geo element camera controller.
        private OrbitGeoElementCameraController _orbitPlaneCameraController;

        // Location camera controller.
        private OrbitLocationCameraController _orbitCraterCameraController;

        // Globe camera controller.
        private readonly GlobeCameraController _globeCameraController = new GlobeCameraController();

        public ChooseCameraController()
        {
            InitializeComponent();
            Initialize();
        }

        private async void Initialize()
        {
            // Create a scene.
            Scene myScene = new Scene(Basemap.CreateImageryWithLabels());

            // Create a surface for elevation data.
            Surface surface = new Surface();
            surface.ElevationSources.Add(new ArcGISTiledElevationSource(_elevationUri));

            // Add the surface to the scene.
            myScene.BaseSurface = surface;

            // Create a graphics overlay for the scene.
            GraphicsOverlay sceneGraphicsOverlay = new GraphicsOverlay()
            {
                SceneProperties = new LayerSceneProperties(SurfacePlacement.Absolute)
            };
            MySceneView.GraphicsOverlays.Add(sceneGraphicsOverlay);

            // Location at the crater.
            MapPoint craterLocation = new MapPoint(-109.929589, 38.437304, 1700, SpatialReferences.Wgs84);

            // Create the plane symbol and make it 10x larger (to be the right size relative to the scene).
            ModelSceneSymbol planeSymbol;
            try
            {
                planeSymbol = await ModelSceneSymbol.CreateAsync(_modelUri, 10.0);
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(ex.Message);
                await new MessageDialog("Loading plane model failed. Sample failed to initialize.", "Sample error").ShowAsync();
                return;
            }

            // Create a graphic using the plane symbol.
            Graphic planeGraphic = new Graphic(new MapPoint(craterLocation.X, craterLocation.Y, 5000.0, SpatialReferences.Wgs84), planeSymbol);
            sceneGraphicsOverlay.Graphics.Add(planeGraphic);

            // Instantiate a new camera controller which orbits a geo element.
            _orbitPlaneCameraController = new OrbitGeoElementCameraController(planeGraphic, 300.0)
            {
                CameraPitchOffset = 30,
                CameraHeadingOffset = 150
            };

            // Instantiate a new camera controller which orbits a location.
            _orbitCraterCameraController = new OrbitLocationCameraController(craterLocation, 6000.0)
            {
                CameraPitchOffset = 3,
                CameraHeadingOffset = 150
            };

            // Set the starting camera controller.
            MySceneView.CameraController = _orbitPlaneCameraController;

            // Enable all of the radio buttons.
            OrbitPlaneButton.IsEnabled = true;
            OrbitCraterButton.IsEnabled = true;
            FreePanButton.IsEnabled = true;

            // Add the scene to the view.
            MySceneView.Scene = myScene;
        }

        private void Setting_Checked(object sender, RoutedEventArgs e)
        {
            switch (((RadioButton)sender).Name)
            {
                case nameof(OrbitPlaneButton):
                    // Switch to the plane camera controller.
                    MySceneView.CameraController = _orbitPlaneCameraController;
                    break;

                case nameof(OrbitCraterButton):
                    // Switch to the crater camera controller.
                    MySceneView.CameraController = _orbitCraterCameraController;
                    break;

                case nameof(FreePanButton):
                    // Switch to a globe camera controller, which is free pan.
                    MySceneView.CameraController = _globeCameraController;
                    break;
            }
        }
    }
}
XAML
<UserControl
    x:Class="ArcGISRuntime.UWP.Samples.ChooseCameraController.ChooseCameraController"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:esriUI="using:Esri.ArcGISRuntime.UI.Controls">
    <Grid>
        <esriUI:SceneView x:Name="MySceneView" />
        <Border Style="{StaticResource BorderStyle}">
            <StackPanel Orientation="Vertical">
                <RadioButton x:Name="OrbitPlaneButton"
                                 GroupName="ColorScheme"
                                 Content="Orbit camera around plane"
                                 Checked="Setting_Checked"
                                 IsEnabled="False"
                                 IsChecked="True" />
                <RadioButton x:Name="OrbitCraterButton"
                                 GroupName="ColorScheme"
                                 Content="Orbit camera around crater"
                                 Checked="Setting_Checked"
                                 IsEnabled="False" />
                <RadioButton x:Name="FreePanButton"
                                 GroupName="ColorScheme"
                                 Content="Free pan around the globe"
                                 Checked="Setting_Checked"
                                 IsEnabled="False" />
            </StackPanel>
        </Border>
    </Grid>
</UserControl>
Examples

Xamarin Forms UWP

Example Name: ChooseCameraController

Control the behavior of the camera in a scene.

Code example screen shot.

C#
// Copyright 2019 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 ArcGISRuntime.Samples.Managers;
using Esri.ArcGISRuntime.Geometry;
using Esri.ArcGISRuntime.Mapping;
using Esri.ArcGISRuntime.Symbology;
using Esri.ArcGISRuntime.UI;
using System;
using System.Threading.Tasks;
using Xamarin.Forms;

namespace ArcGISRuntimeXamarin.Samples.ChooseCameraController
{
    [ArcGISRuntime.Samples.Shared.Attributes.Sample(
        "Choose camera controller",
        "MapView",
        "Control the behavior of the camera in a scene.",
        "Select a radio button to change the camera controller.")]
    [ArcGISRuntime.Samples.Shared.Attributes.OfflineData("681d6f7694644709a7c830ec57a2d72b")]
    public partial class ChooseCameraController : ContentPage
    {
        // Path for elevation data.
        private readonly Uri _elevationUri = new Uri("http://elevation3d.arcgis.com/arcgis/rest/services/WorldElevation3D/Terrain3D/ImageServer");

        // Path for the plane model.
        private readonly Uri _modelUri = new Uri(DataManager.GetDataFolder("681d6f7694644709a7c830ec57a2d72b", "Bristol.dae"));

        // Geo element camera controller.
        private OrbitGeoElementCameraController _orbitPlaneCameraController;

        // Location camera controller.
        private OrbitLocationCameraController _orbitCraterCameraController;

        // Globe camera controller.
        private readonly GlobeCameraController _globeCameraController = new GlobeCameraController();

        // Text labels for the user interface.
        private readonly string[] _controllers = { "Orbit camera around plane", "Orbit camera around crater", "Free pan around the globe" };

        public ChooseCameraController()
        {
            InitializeComponent();
            Initialize();
        }

        private async void Initialize()
        {
            // Create a scene.
            Scene myScene = new Scene(Basemap.CreateImageryWithLabels());

            // Create a surface for elevation data.
            Surface surface = new Surface();
            surface.ElevationSources.Add(new ArcGISTiledElevationSource(_elevationUri));

            // Add the surface to the scene.
            myScene.BaseSurface = surface;

            // Create a graphics overlay for the scene.
            GraphicsOverlay sceneGraphicsOverlay = new GraphicsOverlay()
            {
                SceneProperties = new LayerSceneProperties(SurfacePlacement.Absolute)
            };
            MySceneView.GraphicsOverlays.Add(sceneGraphicsOverlay);

            // Location at the crater.
            MapPoint craterLocation = new MapPoint(-109.929589, 38.437304, 1700, SpatialReferences.Wgs84);

            // Create the plane symbol and make it 10x larger (to be the right size relative to the scene).
            ModelSceneSymbol planeSymbol;
            try
            {
                planeSymbol = await ModelSceneSymbol.CreateAsync(_modelUri, 10.0);
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(ex.Message);
                await Application.Current.MainPage.DisplayAlert("Error", "Loading plane model failed. Sample failed to initialize.", "OK");
                return;
            }

            // Create a graphic using the plane symbol.
            Graphic planeGraphic = new Graphic(new MapPoint(craterLocation.X, craterLocation.Y, 5000.0, SpatialReferences.Wgs84), planeSymbol);
            sceneGraphicsOverlay.Graphics.Add(planeGraphic);

            // Instantiate a new camera controller which orbits a geo element.
            _orbitPlaneCameraController = new OrbitGeoElementCameraController(planeGraphic, 300.0)
            {
                CameraPitchOffset = 30,
                CameraHeadingOffset = 150
            };

            // Instantiate a new camera controller which orbits a location.
            _orbitCraterCameraController = new OrbitLocationCameraController(craterLocation, 6000.0)
            {
                CameraPitchOffset = 3,
                CameraHeadingOffset = 150
            };

            // Set the starting camera controller.
            MySceneView.CameraController = _orbitPlaneCameraController;

            // Add the scene to the view.
            MySceneView.Scene = myScene;
        }

        private void ChangeCameraController(string cameraControllerLabel)
        {
            switch (cameraControllerLabel)
            {
                case "Orbit camera around plane":
                    // Switch to the plane camera controller.
                    MySceneView.CameraController = _orbitPlaneCameraController;
                    break;

                case "Orbit camera around crater":
                    // Switch to the crater camera controller.
                    MySceneView.CameraController = _orbitCraterCameraController;
                    break;

                case "Free pan around the globe":
                    // Switch to a globe camera controller, which is free pan.
                    MySceneView.CameraController = _globeCameraController;
                    break;
            }
        }
        private async void OnButtonClicked(object sender, EventArgs e)
        {
            try
            {
                // Show sheet and get the camera controller from the selection.
                string selectedCamera =
                    await ((Page)Parent).DisplayActionSheet("Select camera controller", "Cancel", null, _controllers);

                // If selected cancel then do nothing.
                if (selectedCamera == "Cancel") return;

                // Change the camera controller to the selected item.
                ChangeCameraController(selectedCamera);
            }
            catch (Exception ex)
            {
                await Application.Current.MainPage.DisplayAlert("Error", ex.ToString(), "OK");
            }
        }
    }
}
XAML
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             xmlns:esriUI="clr-namespace:Esri.ArcGISRuntime.Xamarin.Forms;assembly=Esri.ArcGISRuntime.Xamarin.Forms"
             xmlns:mapping="clr-namespace:Esri.ArcGISRuntime.Mapping;assembly=Esri.ArcGISRuntime"
             x:Class="ArcGISRuntimeXamarin.Samples.ChooseCameraController.ChooseCameraController">
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="*" />
            <RowDefinition Height="auto" />
        </Grid.RowDefinitions>
        <esriUI:SceneView x:Name="MySceneView" Grid.Row="0" />
        <Button x:Name="ControllersButton" Grid.Row="1"
                Text="Change Camera Controller"
                Clicked="OnButtonClicked">
        </Button>
    </Grid>
</ContentPage>
See Also
Additional Examples
Hyperlink to ExampleDescription
Animate3DGraphicAn `OrbitGeoElementCameraController` follows a graphic while the graphic's position and rotation are animated.
ChooseCameraControllerControl the behavior of the camera in a scene.
FeatureLayerExtrusionExtrude features based on their attributes.
UseDistanceCompositeSymChange a graphic's symbol based on the camera's proximity to it.
ViewshedGeoElementAnalyze the viewshed for an object (GeoElement) in a scene.