This sample demonstrates how to use the Line Of Sight component to check whether one or multiple targets are visible from an observer viewpoint in a Scene component.

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 component can be added to the Scene using the following code snippet:

<arcgis-scene item-id="6f0b4bc8d2a24026b5add6d84023efb1">
<!-- include the Line Of Sight component inside the Scene component -->
<arcgis-line-of-sight slot="top-right"></arcgis-line-of-sight>
</arcgis-scene>

The LineOfSightAnalysis can be used to initially create an analysis instance defining an observer and several target points. The observer’s feature reference identifies its building to avoid self-intersections as the building’s level of detail changes.

const analysis = new LineOfSightAnalysis({
observer: {
position: new Point({
latitude: 42.3521,
longitude: -71.0564,
z: 139,
}),
feature: new Graphic({
layer: viewElement.map.layers.find(
(layer) => layer.title === "Boston current buildings - Boston current buildings",
),
attributes: { OBJECTID: 121154 },
}),
},
targets: [
createTarget(42.3492, -71.0529),
createTarget(42.3477, -71.0542),
createTarget(42.3485, -71.0533),
createTarget(42.3467, -71.0549),
],
});

The analysis is then added to the Scene and assigned to the Line Of Sight component.

// add the analysis to the Scene
viewElement.analyses.add(analysis);
// assign the analysis to the component
lineOfSightElement.analysis = analysis;
const analysisView = await viewElement.whenAnalysisView(analysis);

You can retain marker graphics and update their geometries whenever the observer or targets are modified. Reusing the graphics avoids removing and recreating them every time the analysis results change.

The inverted cone tips are placed 5 meters above the intersections to reduce interference with the analysis. These 3D markers can still obstruct other sightlines, depending on the observer and target positions.

const intersectionGraphics = [];
// watch for result changes
reactiveUtils.watch(
() =>
analysisView.results
.toArray()
.map((result) => result?.intersectedLocation)
.filter((location) => location !== null && location !== undefined),
(locations) => {
// Add graphics until there is one for each location
while (intersectionGraphics.length < locations.length) {
const graphic = new Graphic({ symbol: intersectionSymbol });
intersectionGraphics.push(graphic);
viewElement.graphics.add(graphic);
}
// Remove graphics that are no longer needed
const graphicsToRemove = intersectionGraphics.splice(locations.length);
if (graphicsToRemove.length) {
viewElement.graphics.removeMany(graphicsToRemove);
}
// Update every remaining graphic with its current location.
intersectionGraphics.forEach((graphic, index) => {
const location = locations[index];
if (!graphic.geometry?.equals(location)) {
graphic.geometry = location.clone();
}
});
},
{ initial: true },
);

Snapping and tooltips

Snapping is enabled by default in 3D and helps position the observer and targets on vertices and edges of existing features. Hold Ctrl to temporarily toggle snapping on or off. To disable snapping through the Scene component’s view options (beta), set:

viewElement.options.snapping.enabled = false;

This sample enables tooltips through the same view options to enter precise values while placing or editing the observer and targets:

viewElement.options.tooltips.enabled = true;

Press Tab to activate the tooltip’s input mode. Numeric inputs accept simple math expressions with two values and one operator: +, -, *, or /. For example, enter 100 + 2 in an elevation input to use 102 in the input’s current unit. Press Enter to apply the value and close input mode.

Elevation modes

By default, the observer and targets are placed at an absolute elevation relative to sea level. While placing or editing an observer or target, press Tab and use the elevation mode icon next to the tooltip’s Elevation field to select its elevation mode. The observer and each target can use different modes.

The mode determines what the elevation value is measured relative to, not its units:

  • Absolute: Height above sea level, independent of terrain or buildings.
  • On the ground: Positions the point on the terrain surface; its elevation value is ignored.
  • Relative to ground: Height above the terrain at the point’s location.
  • Relative to scene: Height above a scene surface, such as a building roof, with the ground used where no supported scene feature is present.

An elevation of 2 meters in Relative to ground means 2 meters above the local terrain, rather than above sea level. The same numeric elevation can therefore produce different heights in different modes, which can change whether a target is visible from the observer.

3DanalysisLineOfSightLineOfSightAnalysisAnalysisVisibilitytargetobserverreactiveUtilsviewOnReadyarcgis-compassarcgis-line-of-sightarcgis-navigation-togglearcgis-scenearcgis-zoommap-componentscalcite-checkboxcalcite-labelcalcite-panelcalcite-components