Skip to content

Elevation Profile analysis

This sample demonstrates how to create client side elevation profile analysis in a Scene. This analysis allows creating custom elevation profile workflows and accompanying UI. The analysis can be created programmatically and added to the Scene component's analyses collection.

The sample computes and visualizes two profile lines: one for the ground and one for a referenced cable railway feature.

Use dark colors for code blocksCopy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
const analysis = new ElevationProfileAnalysis({
    profiles: [
        // first profile line samples the ground elevation
        {
            type: "ground",
            color: "rgba(150, 75, 0, 0.2)",
        },
        // second profile samples the clicked cabel railway line
        {
            type: "input",
            color: "rgba(30, 160, 220, 1)",
        },
    ],
});
viewElement.analyses.add(analysis);

By accessing the analysis view, one can programmatically start interactive analysis operations, e.g. the pickFeature() method allows to pick a line feature from the scene as an input to the analysis. One can make choosing the input continuous by calling the pickFeature() again after the previous feature was clicked on. This is repeated until either Escape is pressed or abortController.abort() called.

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
20
21
22
23
24
25
26
27
28
29
const analysisView = await viewElement.whenAnalysisView(analysis);

// Use AbortController to stop the picking operation at some later point
let abortController;

async function startPicking() {
    // Stop any pending picking operation.
    abortController?.abort();
    // Create a new abort controller for the new operation and get a reference to its signal.
    abortController = new AbortController();
    const { signal } = abortController;
    try {
        // After one line is picked, call the pickFeature() method again.
        // This is done until the picking is stopped/aborted.
        while (!signal.aborted) {
            // Start picking a feature from the scene and get reference to the returned results.
            const pickedResult = await analysisView.pickFeature({
                signal,
            });
            if (signal.aborted) {
                return;
            }
        }
    } catch (error) {
        if (error.name === "AbortError") {
            console.log("Picking operation was stopped.");
        }
    }
}

The analysis view is also used to access the results of the analysis. The results collection includes information about each initialized profile line, including generation progress state and samples that can be used to create a chart visualization.

Image preview of related sample Analysis objects

Analysis objects

Image preview of related sample Elevation Profile component

Elevation Profile component

Image preview of related sample Area measurement analysis object

Area measurement analysis object

Async cancellation with AbortController

This guide explains how to use AbortController and AbortSignal to cancel asynchronous operations.

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