Perform an exploratory viewshed analysis from a defined vantage point.
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
- Create an
ExploratoryLocationViewshedpassing in the observer location, heading, pitch, horizontal/vertical angles, and min/max distances. - 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
// 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;
}
}