forked from Esri/arcgis-maps-sdk-dotnet-samples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathViewshedLocation.xaml.cs
180 lines (143 loc) · 7.53 KB
/
ViewshedLocation.xaml.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
// 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: https://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 Esri.ArcGISRuntime.Geometry;
using Esri.ArcGISRuntime.Mapping;
using Esri.ArcGISRuntime.Symbology;
using Esri.ArcGISRuntime.UI;
using Esri.ArcGISRuntime.UI.Controls;
using Esri.ArcGISRuntime.UI.GeoAnalysis;
using System;
using System.Drawing;
using Windows.UI.Xaml;
namespace ArcGISRuntime.UWP.Samples.ViewshedLocation
{
[ArcGISRuntime.Samples.Shared.Attributes.Sample(
"Viewshed (Location)",
"Analysis",
"This sample demonstrates the configurable properties of viewshed analysis, including frustum color, heading, pitch, distances, angles, and location.",
"Click anywhere in the scene to change the viewshed observer location.",
"Featured")]
public partial class ViewshedLocation
{
// Hold the URL to the elevation source.
private readonly Uri _localElevationImageService = new Uri("https://scene.arcgis.com/arcgis/rest/services/BREST_DTM_1M/ImageServer");
// Hold the URL to the buildings scene layer.
private readonly Uri _buildingsUrl = new Uri("https://tiles.arcgis.com/tiles/P3ePLMYs2RVChkJx/arcgis/rest/services/Buildings_Brest/SceneServer/layers/0");
// Hold a reference to the viewshed analysis.
private LocationViewshed _viewshed;
// Hold a reference to the analysis overlay that will hold the viewshed analysis.
private AnalysisOverlay _analysisOverlay;
// Graphics overlay for viewpoint symbol.
private GraphicsOverlay _viewpointOverlay;
// Symbol for viewpoint.
private SimpleMarkerSceneSymbol _viewpointSymbol;
// Height of the viewpoint above the ground.
private double _viewHeight;
public ViewshedLocation()
{
InitializeComponent();
// Initialize the sample.
Initialize();
}
private void Initialize()
{
_viewHeight = HeightSlider.Value;
// Create the scene with the imagery basemap.
Scene myScene = new Scene(Basemap.CreateImagery());
MySceneView.Scene = myScene;
// Add the surface elevation.
Surface mySurface = new Surface();
mySurface.ElevationSources.Add(new ArcGISTiledElevationSource(_localElevationImageService));
myScene.BaseSurface = mySurface;
// Add the scene layer.
ArcGISSceneLayer sceneLayer = new ArcGISSceneLayer(_buildingsUrl);
myScene.OperationalLayers.Add(sceneLayer);
// Create the MapPoint representing the initial location.
MapPoint initialLocation = new MapPoint(-4.5, 48.4, 46 + _viewHeight);
// Create the location viewshed analysis.
_viewshed = new LocationViewshed(
initialLocation,
HeadingSlider.Value,
PitchSlider.Value,
HorizontalAngleSlider.Value,
VerticalAngleSlider.Value,
MinimumDistanceSlider.Value,
MaximumDistanceSlider.Value);
// Create a camera based on the initial location.
Camera camera = new Camera(initialLocation, 200.0, 20.0, 70.0, 0.0);
// Create a symbol for the viewpoint.
_viewpointSymbol = SimpleMarkerSceneSymbol.CreateSphere(Color.Blue, 10, SceneSymbolAnchorPosition.Center);
// Add the symbol to the viewpoint overlay.
_viewpointOverlay = new GraphicsOverlay
{
SceneProperties = new LayerSceneProperties(SurfacePlacement.Absolute)
};
_viewpointOverlay.Graphics.Add(new Graphic(initialLocation, _viewpointSymbol));
// Apply the camera to the scene view.
MySceneView.SetViewpointCamera(camera);
// Create an analysis overlay for showing the viewshed analysis.
_analysisOverlay = new AnalysisOverlay();
// Add the viewshed analysis to the overlay.
_analysisOverlay.Analyses.Add(_viewshed);
// Add the analysis overlay to the SceneView.
MySceneView.AnalysisOverlays.Add(_analysisOverlay);
// Add the graphics overlay
MySceneView.GraphicsOverlays.Add(_viewpointOverlay);
// Update the frustum outline Color.
// The frustum outline shows the volume in which the viewshed analysis is performed.
Viewshed.FrustumOutlineColor = Color.Blue;
// Subscribe to tap events. This enables the 'pick up' and 'drop' workflow for moving the viewpoint.
MySceneView.GeoViewTapped += MySceneViewOnGeoViewTapped;
}
private void MySceneViewOnGeoViewTapped(object sender, GeoViewInputEventArgs geoViewInputEventArgs)
{
if (geoViewInputEventArgs.Location == null)
{
// User clicked on the sky - don't update the location with invalid value.
return;
}
// Update the viewshed location.
_viewshed.Location = geoViewInputEventArgs.Location;
// Update the viewshed.
_viewshed.Location = new MapPoint(_viewshed.Location.X, _viewshed.Location.Y, _viewshed.Location.Z + _viewHeight); ;
// Update the viewpoint symbol.
_viewpointOverlay.Graphics.Clear();
_viewpointOverlay.Graphics.Add(new Graphic(_viewshed.Location, _viewpointSymbol));
}
private void HandleSettingsChange(object sender, RoutedEventArgs e)
{
// Return if viewshed hasn't been created yet. This happens when the sample is starting.
if (_viewshed == null)
{
return;
}
// Calculate the difference between the old and new height.
double difference = HeightSlider.Value - _viewHeight;
// Update the view height value to the new value.
_viewHeight = HeightSlider.Value;
// Move the viewshed to the new height.
_viewshed.Location = new MapPoint(_viewshed.Location.X, _viewshed.Location.Y, _viewshed.Location.Z + difference);
// Update the viewshed settings.
_viewshed.Heading = HeadingSlider.Value;
_viewshed.Pitch = PitchSlider.Value;
_viewshed.HorizontalAngle = HorizontalAngleSlider.Value;
_viewshed.VerticalAngle = VerticalAngleSlider.Value;
_viewshed.MinDistance = MinimumDistanceSlider.Value;
_viewshed.MaxDistance = MaximumDistanceSlider.Value;
// Update visibility of the viewshed analysis.
_viewshed.IsVisible = (bool)AnalysisVisibilityCheck.IsChecked;
// Update visibility of the frustum. Note that the frustum will be invisible
// regardless of this setting if the viewshed analysis is not visible.
_viewshed.IsFrustumOutlineVisible = (bool)FrustumVisibilityCheck.IsChecked;
// Update the viewpoint graphic.
_viewpointOverlay.Graphics.Clear();
_viewpointOverlay.Graphics.Add(new Graphic(_viewshed.Location, _viewpointSymbol));
}
}
}