Line of sight widget

This sample demonstrates how to use the LineOfSight widget to check whether one or multiple targets are visible from an observer viewpoint in a SceneView.

In this sample, the observer is set on the upper floor of an existing building. The sample shows how the view of the observer is obstructed if a new building is constructed in front of it. Turn the development layer on and off to see how the view of the river gets obstructed. Move the observer or the targets to explore points where the view is not obstructed. Click on Continue analysis to add more targets to the analysis.

The widget can be added to the scene using the following code snippet:

Use dark colors for code blocksCopy
1
2
3
4
5
const lineOfSight = new LineOfSight({
  view: view
});

view.ui.add(lineOfSight, "top-right");

The LineOfSightViewModel can be used to initially add an observer and several target points.

Use dark colors for code blocksCopy
1
2
3
4
5
6
7
8
9
10
11
12
13

const viewModel = lineOfSight.viewModel;

viewModel.observer = new Point({
  latitude: 42.3521,
  longitude: -71.0559,
  z: 147.139
});

viewModel.targets = [
  createTarget(42.3492, -71.0529),
  createTarget(42.3477, -71.0542)
];

These properties can also be used to watch for changes like adding, moving or removing targets or the observer. Remove a target with right click.

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
// watch when the observer changes
reactiveUtils.watch(() => viewModel.observer, () => {
    setIntersectionMarkers();
});

// watch when a new target is added or removed
viewModel.targets.on("change", (event) => {
  event.added.forEach((target) => {
    setIntersectionMarkers();
    // for each target watch when the intersection changes
    reactiveUtils.watch(() => target.intersectedLocation, () => {
      setIntersectionMarkers();
    });
    event.removed.forEach(() => {
      // remove intersection markers for removed targets (remove with right click on target)
      setIntersectionMarkers();
    });
  });
});

That LineOfSightTarget class gives access to analysis results like the location of the intersection or the graphic that obstructs the view from the observer to the target.

Use dark colors for code blocksCopy
1
2
3
4
5
6
7
8
9
viewModel.targets.forEach((target) => {
  if (target.intersectedLocation) {
    const graphic = new Graphic({
      symbol: intersectionSymbol,
      geometry: target.intersectedLocation
    });
    view.graphics.add(graphic);
  }
});

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