<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no" />
<title>Elevation Profile group | Sample | ArcGIS Maps SDK for JavaScript</title>
<!-- Load the ArcGIS Maps SDK for JavaScript from CDN -->
<script type="module" src="https://js.arcgis.com/5.1/"></script>
arcgis-elevation-profile {
max-width: calc(100vw - 30px);
max-height: calc(100vh - 80px);
transform: translateX(-50%);
<arcgis-scene item-id="2473d6756adf4c45b2b89a8f9e4a2b39">
<arcgis-zoom slot="top-left"></arcgis-zoom>
<arcgis-navigation-toggle slot="top-left"></arcgis-navigation-toggle>
<arcgis-compass slot="top-left"></arcgis-compass>
<arcgis-elevation-profile
></arcgis-elevation-profile>
<calcite-segmented-control id="groundLayerToggle">
<calcite-segmented-control-item value="before" checked>Before landslide</calcite-segmented-control-item>
<calcite-segmented-control-item value="after">After landslide</calcite-segmented-control-item>
</calcite-segmented-control>
const [Collection, Polyline] = await $arcgis.import([
"@arcgis/core/core/Collection.js",
"@arcgis/core/geometry/Polyline.js",
// Get a reference to the scene and elevation profile components
const viewElement = document.querySelector("arcgis-scene");
const arcgisElevationProfile = document.querySelector("arcgis-elevation-profile");
// Wait for the view to initialize
await viewElement.viewOnReady();
const profileLine = new Polyline({
[-13564719.101959955, 6154408.153564724, 0],
[-13564115.888797166, 6154244.615736664, 0],
const groundLayers = viewElement.map.ground.layers;
const beforeLandslideLayer = groundLayers.find((layer) => layer.title === "ELEV__3857__US_Oso__LandslideBefore");
const afterLandslideLayer = groundLayers.find((layer) => layer.title === "ELEV__3857__US_Oso__LandslideAfter");
const terrain3DLayer = groundLayers.find((layer) => layer.title?.includes("Terrain3D"));
if (!beforeLandslideLayer || !afterLandslideLayer) {
throw new Error("One or more Oso elevation layers were not found in the WebScene ground layers.");
throw new Error("The default terrain 3D elevation layer was not found in the WebScene ground layers.");
const groundLayerToggle = document.getElementById("groundLayerToggle");
const groundLayerOptions = {
before: beforeLandslideLayer,
after: afterLandslideLayer,
const moveGroundLayerToTop = (layer) => {
groundLayers.reorder(layer, groundLayers.length - 1);
moveGroundLayerToTop(beforeLandslideLayer);
// Full-opacity profile line colors for the active state (before/after landslide).
beforeLandslide: "#F97316",
afterLandslide: "#DC2626",
terrainContext: "#2563EB",
// Shared opacity for whichever profile line is not active.
const inactiveLineOpacity = 0.4;
const transparentProfileColors = {
beforeLandslide: `rgba(249, 115, 22, ${inactiveLineOpacity})`,
afterLandslide: `rgba(220, 38, 38, ${inactiveLineOpacity})`,
// Setup grouped elevation profiles
arcgisElevationProfile.profiles = new Collection([
profiles: new Collection([
title: "Pre-Landslide (March 2014)",
source: beforeLandslideLayer,
color: profileColors.beforeLandslide,
title: "Post-Landslide (April 2014)",
source: afterLandslideLayer,
color: profileColors.afterLandslide,
title: "Regional context",
profiles: new Collection([
title: `${terrain3DLayer.title} (${new Date().getFullYear()})`,
color: profileColors.terrainContext,
indicatorPointVisible: false,
const surveyProfiles = arcgisElevationProfile.profiles.getItemAt(0).profiles;
const preLandslideProfile = surveyProfiles.getItemAt(0);
const postLandslideProfile = surveyProfiles.getItemAt(1);
const updateProfileLineStyling = (state) => {
const isBeforeState = state === "before";
// In each state, keep the current line vivid and dim the other one.
preLandslideProfile.color = isBeforeState
? profileColors.beforeLandslide
: transparentProfileColors.beforeLandslide;
postLandslideProfile.color = isBeforeState
? transparentProfileColors.afterLandslide
: profileColors.afterLandslide;
updateProfileLineStyling("before");
groundLayerToggle.addEventListener("calciteSegmentedControlChange", (event) => {
const state = event.target.value;
moveGroundLayerToTop(groundLayerOptions[state]);
updateProfileLineStyling(state);
// Set the default polyline along which the elevation is sampled
arcgisElevationProfile.geometry = profileLine;