Line of sight widget

Explore in the sandboxView live

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:

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.

  = 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 or moving new targets or the observer.

// watch when the observer changes"observer", function(value) {

// watch when a new target is added or removed
viewModel.targets.on("change", function(event) {
  event.added.forEach((target) => {
    // for each target watch when the intersection changes"intersectedLocation", function() {

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.

viewModel.targets.forEach(function(target) {
  if (target.intersectedLocation) {
    const graphic = new Graphic({
      symbol: intersectionSymbol,
      geometry: target.intersectedLocation