This sample demonstrates how to create client side analyses in a Scene component.

If you are new to the API, start with Introduction to analyses for the general model and lifecycle of an analysis object and analysis view.

Analyses allow creating custom measuring or visibility analysis workflows and accompanying UI without the use of respective components. The sample covers the following types:

These objects can be created programmatically and added to the Scene component’s analyses collection.

The following snippets use the SliceAnalysis as an example:

const analysis = new SliceAnalysis({
shape: new SlicePlane({
position: new Point({
x: -8238840,
y: 4971700,
z: 21,
spatialReference: SpatialReference.WebMercator,
}),
tilt: 0,
width: 70,
height: 100,
heading: 278,
}),
});
viewElement.analyses.add(analysis);

By accessing the respective analysis view, one can programmatically start interactive analysis operations. For example, an already existing analysis geometry can be edited by enabling the interactive property.

const analysisView = await viewElement.whenAnalysisView(analysis);
analysisView.interactive = true;

With the place() method it is possible to start placing a new analysis. Once placement completes successfully, the analysis remains interactive so its geometry can be edited immediately. For viewsheds and dimensions, the newly placed item is selected for editing.

const abortController = new AbortController();
try {
// Pass the signal as an argument to the interactive place method.
await analysisView.place({
signal: abortController.signal,
});
// Keep the completed analysis interactive for editing.
analysisView.interactive = true;
} catch (error) {
// Avoid logging the abort errors.
if (!promiseUtils.isAbortError(error)) {
throw error;
}
}

Placement completes according to the analysis view’s interaction rules. Pressing Escape also ends placement. For line of sight, the “Finish” button provides an alternative to Escape and enables editing when an observer has been placed. Canceling placement preserves a valid new measurement or slice. If the replacement is invalid, the previous analysis is restored instead of entering editing.

To stop placement programmatically, call abort() on the controller whose signal was passed to place().

abortController.abort();

Before switching tools, editing, or clearing an analysis, the sample waits for the pending placement operation to finish cleaning up. This prevents an active placement from updating an analysis after it has been cleared.

async function stopPlacement() {
const operation = placement;
if (operation) {
operation.controller.abort();
await operation.settled;
}
}
3DanalysisAnalysisObjectAnalysismeasurementDirectLineMeasurement3DAnalysisAreaMeasurement3DAnalysisLineOfSightAnalysisSliceAnalysisViewshedAnalysisDimensionAnalysisVolumeMeasurementAnalysisVisibilityviewOnReadyAbortControllerarcgis-compassarcgis-navigation-togglearcgis-scenearcgis-zoomarcgisViewKeyDownmap-componentscalcite-actioncalcite-action-barcalcite-buttoncalcite-labelcalcite-tooltipcalcite-components