3D Elevation Exaggeration

Download Samples Repository

Description

Demonstrates elevation exaggeration in a scene.

"Desktop" "Store" Available for Desktop, Store

Sample Code

<UserControl x:Class="ArcGISRuntime.Samples.Desktop.ElevationExaggeration"
			 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" 
			 xmlns:esri="http://schemas.esri.com/arcgis/runtime/2013"
			 mc:Ignorable="d" >
	<Grid>
		<esri:SceneView x:Name="MySceneView" LayerLoaded="MySceneView_LayerLoaded">
			<esri:Scene>
				<esri:Scene.Surface>
					<esri:ServiceElevationSource ServiceUri="http://elevation3d.arcgis.com/arcgis/rest/services/WorldElevation3D/Terrain3D/ImageServer" 
												 IsEnabled="True" />
				</esri:Scene.Surface>
				<esri:ArcGISTiledMapServiceLayer ID="AGOLayer" 
												 ServiceUri="http://services.arcgisonline.com/arcgis/rest/services/World_Imagery/MapServer" />
				<esri:GraphicsLayer ID="AbsoluteModeGraphicsLayer">
					<esri:GraphicsLayer.SceneProperties>
						<esri:LayerSceneProperties SurfacePlacement="Absolute"/>
					</esri:GraphicsLayer.SceneProperties>
				</esri:GraphicsLayer>
				<esri:GraphicsLayer ID="DrapedModeGraphicsLayer">
					<esri:GraphicsLayer.SceneProperties>
						<esri:LayerSceneProperties SurfacePlacement="Draped"/>
					</esri:GraphicsLayer.SceneProperties>
				</esri:GraphicsLayer>
				<esri:GraphicsLayer ID="RelativeModeGraphicsLayer">
					<esri:GraphicsLayer.SceneProperties>
						<esri:LayerSceneProperties SurfacePlacement="Relative"/>
					</esri:GraphicsLayer.SceneProperties>
				</esri:GraphicsLayer>
			</esri:Scene>
		</esri:SceneView>

		<Grid HorizontalAlignment="Right" VerticalAlignment="Top" Margin="0,15,15,0">
			<Rectangle Stroke="Gray" RadiusX="10" RadiusY="10" Fill="#77919191" Margin="0,0,0,5" />
			<StackPanel>
				<StackPanel Orientation="Horizontal" Margin="0,5,0,0">
					<Ellipse Fill="Yellow" Height="30" Width="30" Margin="5"
							 StrokeThickness="2" Stroke="White"/>
					<TextBlock Text="Draped" Margin="5" Foreground="White"/>
				</StackPanel>
				<StackPanel Orientation="Horizontal">
					<Ellipse Fill="Red" Height="30" Width="30" Margin="5"
							 StrokeThickness="2" Stroke="White"/>
					<TextBlock Text="Absolute" Margin="5" Foreground="White"/>
				</StackPanel>
				<StackPanel Orientation="Horizontal" Margin="0,0,0,10">
					<Ellipse Fill="LightBlue" Height="30" Width="30"
							 Margin="5" StrokeThickness="2" Stroke="White"/>
					<TextBlock Text="Relative" Margin="5" Foreground="White"/>
				</StackPanel>
			</StackPanel>
		</Grid>

		<Grid HorizontalAlignment="Left" VerticalAlignment="Top" Margin="15,15,0,0">
			<Rectangle Stroke="Gray" RadiusX="10" RadiusY="10" Fill="#77919191" />
			<StackPanel Orientation="Horizontal" Margin="5,10,10,0">
				<RadioButton Tag="Point" Margin="5,0,0,0" Foreground="White"
							 GroupName="Shapes" Content="Point" Checked="RadioButton_Checked"/>
				<RadioButton Tag="Line" Margin="5,0,0,0" Foreground="White" 
							 GroupName="Shapes" Content="Line" Checked="RadioButton_Checked"/>
				<RadioButton Tag="Polygon" Margin="5,0,0,0" Foreground="White" 
							 GroupName="Shapes" Content="Polygon" Checked="RadioButton_Checked"/>
			</StackPanel>

			<StackPanel Background="Transparent" Margin="10,40,15,0" HorizontalAlignment="Left" VerticalAlignment="Top">
				<TextBlock Text="Elevation Exaggeration" Foreground="White" Margin="10,0,0,5" />
                <Slider x:Name="ElevationExaggerationSlider" Minimum="1" Maximum="5" TickFrequency="1"
                        ValueChanged="OnElevationExaggerationChanged" Margin="10,5,0,10"/>
			</StackPanel>
		</Grid>
	</Grid>
</UserControl>
using Esri.ArcGISRuntime.Controls;
using Esri.ArcGISRuntime.Geometry;
using Esri.ArcGISRuntime.Layers;
using Esri.ArcGISRuntime.Symbology;
using System.Collections.Generic;
using System.Linq;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;

namespace ArcGISRuntime.Samples.Desktop
{
	/// <summary>
	/// Demonstrates elevation exaggeration in a scene.
	/// </summary>
	/// <title>3D Elevation Exaggeration</title>
	/// <category>Scene</category>
	/// <subcategory>Mapping</subcategory>
	public partial class ElevationExaggeration : UserControl
	{
		private List<MapPoint> _coordinates = new List<MapPoint>();
		private GraphicsLayer _absoluteModeGL;
		private GraphicsLayer _relativeModeGL;
		private GraphicsLayer _drapedModeGL;

		public ElevationExaggeration()
		{
			InitializeComponent();

			_coordinates.Add(new MapPoint(-106.981, 39.028, 6000, SpatialReferences.Wgs84));
			_coordinates.Add(new MapPoint(-106.956, 39.081, 6000, SpatialReferences.Wgs84));
			_coordinates.Add(new MapPoint(-106.869, 39.081, 6000, SpatialReferences.Wgs84));
			_coordinates.Add(new MapPoint(-106.879, 39.014, 6000, SpatialReferences.Wgs84));

			_absoluteModeGL = MySceneView.Scene.Layers["AbsoluteModeGraphicsLayer"] as GraphicsLayer;
			_relativeModeGL = MySceneView.Scene.Layers["RelativeModeGraphicsLayer"] as GraphicsLayer;
			_drapedModeGL = MySceneView.Scene.Layers["DrapedModeGraphicsLayer"] as GraphicsLayer;

		}

		private void MySceneView_LayerLoaded(object sender, Esri.ArcGISRuntime.Controls.LayerLoadedEventArgs e)
		{
			if (e.LoadError == null)
			{
				if (e.Layer.ID == "AGOLayer")
					MySceneView.SetView(new Camera(new MapPoint(-106.882128302391, 38.7658957449754, 12994.1727461051), 
						358.607816178049, 70.0562968167998));
			}
		}

		private void RadioButton_Checked(object sender, RoutedEventArgs e)
		{
			ClearAll();

			string shapeTag = (string)((RadioButton)sender).Tag;
			switch (shapeTag)
			{
				case "Point":
					GraphicCollection absoluteGC = new GraphicCollection();
					GraphicCollection relativeGC = new GraphicCollection();
					GraphicCollection drapedGC = new GraphicCollection();

					foreach (MapPoint mp in _coordinates)
					{
						absoluteGC.Add(new Graphic(mp, GetPointSymbol(SurfacePlacement.Absolute)));
						relativeGC.Add(new Graphic(mp, GetPointSymbol(SurfacePlacement.Relative)));
						drapedGC.Add(new Graphic(mp, GetPointSymbol(SurfacePlacement.Draped)));
					}

					_absoluteModeGL.Graphics.AddRange(absoluteGC);
					_relativeModeGL.Graphics.AddRange(relativeGC);
					_drapedModeGL.Graphics.AddRange(drapedGC);

					break;
				case "Line":
					var line = new Polyline(_coordinates, SpatialReferences.Wgs84);
					_absoluteModeGL.Graphics.Add(new Graphic(line, GetPolylineSymbol(SurfacePlacement.Absolute)));
					_relativeModeGL.Graphics.Add(new Graphic(line, GetPolylineSymbol(SurfacePlacement.Relative)));
					_drapedModeGL.Graphics.Add(new Graphic(line, GetPolylineSymbol(SurfacePlacement.Draped)));
					break;
				case "Polygon":
					var polygon = new Polygon(_coordinates, SpatialReferences.Wgs84);
					_absoluteModeGL.Graphics.Add(new Graphic(polygon, GetPolygonSymbol(SurfacePlacement.Absolute)));
					_relativeModeGL.Graphics.Add(new Graphic(polygon, GetPolygonSymbol(SurfacePlacement.Relative)));
					_drapedModeGL.Graphics.Add(new Graphic(polygon, GetPolygonSymbol(SurfacePlacement.Draped)));
					break;
			}
		}

		private void ClearAll()
		{
			IEnumerable<GraphicsLayer> graphicLayers = MySceneView.Scene.Layers.Where(l => l is GraphicsLayer).Cast<GraphicsLayer>();
			foreach (GraphicsLayer gl in graphicLayers)
				gl.Graphics.Clear();
		}

		private Esri.ArcGISRuntime.Symbology.Symbol GetPolylineSymbol(SurfacePlacement mode)
		{
			SimpleLineSymbol sls = new SimpleLineSymbol()
			{
				Style = SimpleLineStyle.Solid,
				Color = mode == SurfacePlacement.Absolute ?
                    Colors.Red : mode == SurfacePlacement.Draped ? Colors.Yellow : Colors.LightBlue,
				Width = 4
			};
			
			return sls;
		}

		private Esri.ArcGISRuntime.Symbology.Symbol GetPolygonSymbol(SurfacePlacement mode)
		{
            SimpleFillSymbol sfs = new SimpleFillSymbol()
            {
                Style = SimpleFillStyle.Solid,
                Color = mode == SurfacePlacement.Absolute ?
                    Colors.Red : mode == SurfacePlacement.Draped ? Colors.Yellow : Colors.LightBlue
			};
			
			return sfs;
		}

		private Esri.ArcGISRuntime.Symbology.Symbol GetPointSymbol(SurfacePlacement mode)
		{
			SimpleMarkerSymbol sms = new SimpleMarkerSymbol()
			{
				Style = SimpleMarkerStyle.Circle,
				Color = mode == SurfacePlacement.Absolute ? 
                    Colors.Red : mode == SurfacePlacement.Draped ? Colors.Yellow : Colors.LightBlue,
				Size = 20
			};
			
			return sms;
		}

		private void OnElevationExaggerationChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
		{
			MySceneView.ElevationExaggeration = (sender as Slider).Value;
		}
	}
}
Feedback on this topic?