Skip To ContentArcGIS for DevelopersSign In Dashboard
Loading...

Note: Support for 3D on mobile devices may vary, view the system requirements for more information.

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.

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

// watch when the observer changes
viewModel.watch("observer", function(value) {
    setIntersectionMarkers();
});

// watch when a new target is added or removed
viewModel.targets.on("change", function(event) {
  event.added.forEach((target) => {
    setIntersectionMarkers();
    // for each target watch when the intersection changes
    target.watch("intersectedLocation", function() {
      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.

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

Sample search results

TitleSample
Loading...