Skip to content
View on GitHub

Perform an exploratory viewshed analysis from a defined vantage point.

Image of show exploratory viewshed from point in scene

Use case

An exploratory viewshed analysis is a type of visual analysis you can perform on a scene. The exploratory viewshed shows what can be seen from a given location. The output is an overlay with two different colors - one representing the visible areas (green) and the other representing the obstructed areas (red).

Note: This analysis is a form of "exploratory analysis", which means the results are calculated on the current scale of the data, and the results are generated very quickly but not persisted. If persisted analysis performed at the full resolution of the data is required, consider using a ViewshedFunction to perform a viewshed calculation instead.

How to use the sample

Tap a location on the map to change the location of the exploratory viewshed observation point.

Tap the "Settings" button at the bottom of the screen to show the controls to change the exploratory viewshed settings. The rendered exploratory viewshed will update in real time as the values are adjusted.

How it works

  1. Create an ExploratoryLocationViewshed passing in the observer location, heading, pitch, horizontal/vertical angles, and min/max distances.
  2. Set the property values on the viewshed instance for location, direction, range, and visibility properties.

Relevant API

  • AnalysisOverlay
  • ArcGISSceneLayer
  • ArcGISTiledElevationSource
  • ExploratoryLocationViewshed
  • ExploratoryViewshed

About the data

The scene shows a buildings layer in Brest, France hosted on ArcGIS Online.

Tags

3D, exploratory viewshed, frustum, scene, visibility analysis

Sample Code

show_exploratory_viewshed_from_point_in_scene.dart
Use dark colors for code blocksCopy
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
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
// Copyright 2025 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.
//

import 'package:arcgis_maps/arcgis_maps.dart';
import 'package:arcgis_maps_sdk_flutter_samples/common/common.dart';
import 'package:flutter/material.dart';

class ShowExploratoryViewshedFromPointInScene extends StatefulWidget {
  const ShowExploratoryViewshedFromPointInScene({super.key});

  @override
  State<ShowExploratoryViewshedFromPointInScene> createState() =>
      _ShowExploratoryViewshedFromPointInSceneState();
}

class _ShowExploratoryViewshedFromPointInSceneState
    extends State<ShowExploratoryViewshedFromPointInScene>
    with SampleStateSupport {
  // Create a controller for the scene view.
  final _sceneViewController = ArcGISSceneView.createController();

  // A flag indicating whether to show the settings bottom sheet.
  bool _settingsVisible = false;

  // Viewshed state variables.
  double _heading = 20;
  double _pitch = 70;
  double _horizontalAngle = 45;
  double _verticalAngle = 90;
  double _height = 100;
  double _minDistance = 5;
  double _maxDistance = 1000;
  bool _showFrustum = false;
  bool _showAnalysis = true;
  late final ExploratoryLocationViewshed _exploratoryViewshed;

  // A flag for when the scene view is ready and controls can be used.
  var _ready = false;

  @override
  void initState() {
    super.initState();

    // Initialize the exploratory location viewshed.
    _exploratoryViewshed = ExploratoryLocationViewshed.withLocation(
      location: ArcGISPoint(
        x: -4.50,
        y: 48.4,
        z: _height,
        spatialReference: SpatialReference.wgs84,
      ),
      heading: _heading,
      pitch: _pitch,
      horizontalAngle: _horizontalAngle,
      verticalAngle: _verticalAngle,
      minDistance: _minDistance,
      maxDistance: _maxDistance,
    );
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: SafeArea(
        top: false,
        left: false,
        right: false,
        child: Stack(
          children: [
            Column(
              children: [
                Expanded(
                  // Add a scene view to the widget tree and set a controller.
                  child: ArcGISSceneView(
                    controllerProvider: () => _sceneViewController,
                    onSceneViewReady: onSceneViewReady,
                    onTap: onTap,
                  ),
                ),
                Row(
                  mainAxisAlignment: MainAxisAlignment.spaceEvenly,
                  children: [
                    // Button to show the exploratory viewshed options.
                    ElevatedButton(
                      onPressed: () => setState(() => _settingsVisible = true),
                      child: const Text('Settings'),
                    ),
                  ],
                ),
              ],
            ),
            // Display a progress indicator and prevent interaction until state is ready.
            LoadingIndicator(visible: !_ready),
          ],
        ),
      ),
      bottomSheet: _settingsVisible ? buildSettings(context) : null,
    );
  }

  Widget buildSettings(BuildContext context) {
    // Create the BottomSheet containing the exploratory viewshed adjustment controls.
    return BottomSheetSettings(
      onCloseIconPressed: () => setState(() => _settingsVisible = false),
      settingsWidgets: (context) => [
        SizedBox(
          height: 250,
          child: SingleChildScrollView(
            child: Column(
              children: [
                Table(
                  columnWidths: const <int, TableColumnWidth>{
                    0: IntrinsicColumnWidth(),
                    1: FlexColumnWidth(),
                    2: IntrinsicColumnWidth(),
                  },
                  defaultVerticalAlignment: TableCellVerticalAlignment.middle,
                  children: [
                    TableRow(
                      children: [
                        const Text('Heading:'),
                        LayoutBuilder(
                          builder: (context, constraints) {
                            return SizedBox(
                              width: constraints.maxWidth * 0.6,
                              child: Slider(
                                value: _heading,
                                max: 360,
                                label: _heading.round().toString(),
                                onChanged: (value) {
                                  _exploratoryViewshed.heading = value;
                                  setState(() => _heading = value);
                                },
                              ),
                            );
                          },
                        ),
                        Text(
                          _heading.round().toString(),
                          textAlign: TextAlign.end,
                        ),
                      ],
                    ),
                    TableRow(
                      children: [
                        const Text('Pitch:'),
                        LayoutBuilder(
                          builder: (context, constraints) {
                            return SizedBox(
                              width: constraints.maxWidth * 0.6,
                              child: Slider(
                                value: _pitch,
                                max: 180,
                                label: _pitch.round().toString(),
                                onChanged: (value) {
                                  _exploratoryViewshed.pitch = value;
                                  setState(() => _pitch = value);
                                },
                              ),
                            );
                          },
                        ),
                        Text(
                          _pitch.round().toString(),
                          textAlign: TextAlign.end,
                        ),
                      ],
                    ),
                    TableRow(
                      children: [
                        const Text('Horizontal angle:'),
                        LayoutBuilder(
                          builder: (context, constraints) {
                            return SizedBox(
                              width: constraints.maxWidth * 0.6,
                              child: Slider(
                                value: _horizontalAngle,
                                max: 360,
                                onChanged: (value) {
                                  _exploratoryViewshed.horizontalAngle = value;
                                  setState(() => _horizontalAngle = value);
                                },
                              ),
                            );
                          },
                        ),
                        Text(
                          _horizontalAngle.round().toString(),
                          textAlign: TextAlign.end,
                        ),
                      ],
                    ),
                    TableRow(
                      children: [
                        const Text('Vertical angle:'),
                        LayoutBuilder(
                          builder: (context, constraints) {
                            return SizedBox(
                              width: constraints.maxWidth * 0.6,
                              child: Slider(
                                value: _verticalAngle,
                                max: 360,
                                onChanged: (value) {
                                  _exploratoryViewshed.verticalAngle = value;
                                  setState(() => _verticalAngle = value);
                                },
                              ),
                            );
                          },
                        ),
                        Text(
                          _verticalAngle.round().toString(),
                          textAlign: TextAlign.end,
                        ),
                      ],
                    ),
                    TableRow(
                      children: [
                        const Text('Height:'),
                        LayoutBuilder(
                          builder: (context, constraints) {
                            return SizedBox(
                              width: constraints.maxWidth * 0.6,
                              child: Slider(
                                value: _height,
                                min: 10,
                                max: 300,
                                onChanged: (value) {
                                  _exploratoryViewshed.location = ArcGISPoint(
                                    x: _exploratoryViewshed.location.x,
                                    y: _exploratoryViewshed.location.y,
                                    z: value,
                                    spatialReference: SpatialReference.wgs84,
                                  );
                                  setState(() => _height = value);
                                },
                              ),
                            );
                          },
                        ),
                        Text(
                          _height.round().toString(),
                          textAlign: TextAlign.end,
                        ),
                      ],
                    ),
                    TableRow(
                      children: [
                        const Text('Min distance:'),
                        LayoutBuilder(
                          builder: (context, constraints) {
                            return SizedBox(
                              width: constraints.maxWidth * 0.6,
                              child: Slider(
                                value: _minDistance,
                                max: 50,
                                onChanged: (value) {
                                  _exploratoryViewshed.minDistance = value;
                                  setState(() => _minDistance = value);
                                },
                              ),
                            );
                          },
                        ),
                        Text(
                          _minDistance.round().toString(),
                          textAlign: TextAlign.end,
                        ),
                      ],
                    ),
                    TableRow(
                      children: [
                        const Text('Max distance:'),
                        LayoutBuilder(
                          builder: (context, constraints) {
                            return SizedBox(
                              width: constraints.maxWidth * 0.6,
                              child: Slider(
                                value: _maxDistance,
                                min: 100,
                                max: 5000,
                                onChanged: (value) {
                                  _exploratoryViewshed.maxDistance = value;
                                  setState(() => _maxDistance = value);
                                },
                              ),
                            );
                          },
                        ),
                        Text(
                          _maxDistance.round().toString(),
                          textAlign: TextAlign.end,
                        ),
                      ],
                    ),
                  ],
                ),
                Row(
                  children: [
                    const Text('Show frustum:'),
                    const Spacer(),
                    Switch(
                      value: _showFrustum,
                      onChanged: (value) {
                        _exploratoryViewshed.frustumOutlineVisible = value;
                        setState(() => _showFrustum = value);
                      },
                    ),
                  ],
                ),
                Row(
                  children: [
                    const Text('Show viewshed:'),
                    const Spacer(),
                    Switch(
                      value: _showAnalysis,
                      onChanged: (value) {
                        _exploratoryViewshed.isVisible = value;
                        setState(() => _showAnalysis = value);
                      },
                    ),
                  ],
                ),
              ],
            ),
          ),
        ),
      ],
    );
  }

  void onSceneViewReady() {
    // Get scene with basemap, surface, and initial viewpoint.
    final scene = _setupScene();

    // Add a buildings scene layer.
    final buildingLayerUri = Uri.parse(
      'https://tiles.arcgis.com/tiles/P3ePLMYs2RVChkJx/arcgis/rest/services/Buildings_Brest/SceneServer/layers/0',
    );
    final buildingsLayer = ArcGISSceneLayer.withUri(buildingLayerUri);
    scene.operationalLayers.add(buildingsLayer);

    // Add the scene to the view controller.
    _sceneViewController.arcGISScene = scene;

    // Create an AnalysisOverlay and add the viewshed.
    final analysisOverlay = AnalysisOverlay();
    analysisOverlay.analyses.add(_exploratoryViewshed);

    // Add the AnalysisOverlay to the view controller.
    _sceneViewController.analysisOverlays.add(analysisOverlay);

    // Set the ready state variable to true to enable the sample UI.
    setState(() => _ready = true);
  }

  void onTap(Offset offset) {
    final tapLocation = _sceneViewController.screenToBaseSurface(
      screen: offset,
    );
    if (tapLocation == null) return;

    // Set the new exploratory viewshed location using the x and y values from the tap point
    // and the current viewshed height.
    _exploratoryViewshed.location = ArcGISPoint(
      x: tapLocation.x,
      y: tapLocation.y,
      z: _height,
      spatialReference: SpatialReference.wgs84,
    );
  }

  ArcGISScene _setupScene() {
    // Create a scene with an imagery basemap style.
    final scene = ArcGISScene.withBasemapStyle(BasemapStyle.arcGISImagery);

    // Setup the initial viewpoint for the scene.
    final camera = Camera.withLookAtPoint(
      lookAtPoint: ArcGISPoint(
        x: -4.50,
        y: 48.4,
        z: 100,
        spatialReference: SpatialReference.wgs84,
      ),
      distance: 200,
      heading: 20,
      pitch: 70,
      roll: 0,
    );
    scene.initialViewpoint = Viewpoint.withExtentCamera(
      targetExtent: camera.location,
      camera: camera,
    );

    // Add surface elevation to the scene.
    final worldElevationService = Uri.parse(
      'https://elevation3d.arcgis.com/arcgis/rest/services/WorldElevation3D/Terrain3D/ImageServer',
    );
    final elevationSource = ArcGISTiledElevationSource.withUri(
      worldElevationService,
    );
    scene.baseSurface.elevationSources.add(elevationSource);

    return scene;
  }
}

Your browser is no longer supported. Please upgrade your browser for the best experience. See our browser deprecation post for more details.