Skip to content

Show line of sight between points

View on GitHub

Perform a line of sight analysis between two points in real time.

Image of show line of sight between points

Use case

A line of sight analysis can be used to assess whether a view is obstructed between an observer and a target. Obstructing features could either be natural, like topography, or man-made, like buildings. Consider an events planning company wanting to commemorate a national event by lighting sequential beacons across hill summits or roof tops. To guarantee a successful event, ensuring an unobstructed line of sight between neighboring beacons would allow each beacon to be activated as intended.

How to use the sample

The sample loads with a preset observer and target location, linked by a colored line. A red segment on the line means the view between observer and target is obstructed, whereas green means the view is unobstructed.

Tap the scene to set the location of the observer. Long press to set the line-of-sight target location.

How it works

  1. Create an AnalysisOverlay and add it to the scene view.
  2. Create a LocationLineOfSight with initial observer and target locations and add it to the analysis overlay.
  3. Set onTap and onLongPress handler functions when creating the ArcGISSceneView. Use the ArcGISSceneViewController.screenToBaseSurface(Offset screenOffset) function to convert the screen offset to an ArcGISPoint on the scene. In the onTap function, set the LocationLineOfSight.observerLocation property. In the onLongPress function, set the LocationLineOfSight.targetLocation property.
  4. The AnalysisOverlay will automatically update when either of the locations are updated.

Relevant API

  • AnalysisOverlay
  • ArcGISSceneView
  • LocationLineOfSight

Tags

3D, line of sight, visibility, visibility analysis

Sample Code

show_line_of_sight_between_points.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
// 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 ShowLineOfSightBetweenPoints extends StatefulWidget {
  const ShowLineOfSightBetweenPoints({super.key});

  @override
  State<ShowLineOfSightBetweenPoints> createState() =>
      _ShowLineOfSightBetweenPointsState();
}

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

  // The LocationLineOfSight object that will provide line-of-sight analysis for this sample.
  // The object is initialized with the starting observer and target locations.
  final _locationLineOfSight = LocationLineOfSight(
    observerLocation: ArcGISPoint(
      x: -73.095827750063904,
      y: -49.319214695380957,
      z: 2697.4689045762643,
      spatialReference: SpatialReference.wgs84,
    ),
    targetLocation: ArcGISPoint(
      x: -73.125568047959803,
      y: -49.347049722534479,
      z: 1944.1079967124388,
      spatialReference: SpatialReference.wgs84,
    ),
  );

  // A flag for when the scene view is ready.
  var _ready = false;

  @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,
                    onLongPressEnd: onLongPressEnd,
                  ),
                ),
                const Column(
                  mainAxisAlignment: MainAxisAlignment.spaceEvenly,
                  children: [
                    Text('Tap to set new observation point.'),
                    Text('Long press to set new target point.'),
                    Divider(),
                    Text('Green: Visible from the observation point.'),
                    Text('Red: Not visible from the observation point.'),
                    Text('Hidden: Segment is obscured by terrain.'),
                  ],
                ),
              ],
            ),
            // Display a progress indicator and prevent interaction until state is ready.
            LoadingIndicator(visible: !_ready),
          ],
        ),
      ),
    );
  }

  void onSceneViewReady() {
    // Create the scene for this sample and set it on the view controller.
    final scene = _setupScene();
    _sceneViewController.arcGISScene = scene;

    // Create an AnalysisOverlay and add the LocationLineOfSight object to it.
    final analysisOverlay = AnalysisOverlay();
    analysisOverlay.analyses.add(_locationLineOfSight);

    // 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) {
    // Get the new observer point from the screen tap offset.
    final newObserverPoint = _sceneViewController.screenToBaseSurface(
      screen: offset,
    );
    // Return if a point could not be returned.
    if (newObserverPoint == null) return;

    // Set the new origin point on the analysis object.
    _locationLineOfSight.observerLocation = newObserverPoint;
  }

  void onLongPressEnd(Offset offset) {
    // Get the new target point from the long press offset.
    final newTargetPoint = _sceneViewController.screenToBaseSurface(
      screen: offset,
    );
    // Return if a point could not be returned.
    if (newTargetPoint == null) return;

    // Set the new origin point on the analysis object.
    _locationLineOfSight.targetLocation = newTargetPoint;
  }

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

    // Set the scene's initial viewpoint.
    scene.initialViewpoint = Viewpoint.withPointScaleCamera(
      center: ArcGISPoint(x: 0, y: 0),
      scale: 1,
      camera: Camera.withLookAtPoint(
        lookAtPoint: ArcGISPoint(
          x: -73.1094,
          y: -49.3325,
          z: 2210,
          spatialReference: SpatialReference.wgs84,
        ),
        distance: 10000,
        heading: 150,
        pitch: 20,
        roll: 0,
      ),
    );

    // 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.