Skip to content

This sample demonstrates how to build a measurement experience with Map components and a Calcite Action Bar.

The app displays the same map content in both a 2D Map and a 3D Scene by assigning them a shared Map instance (a basemap TileLayer plus a FeatureLayer). The toolbar buttons control which measurement component is visible and active.

The sample tracks state with variables (activeDimension: 2D/3D, activeTool: distance/area). Clicking a tool button shows the correct measurement component for the current view and calls start().

// State tracked independently of the Measurement components to manage UI and interactions.
let activeDimension = "2d"; // "2d" | "3d"
let activeTool = null; // null | "distance" | "area"
function startTool(toolName) {
activeTool = toolName;
const currentTools = toolElements[activeDimension];
const toolToShow = currentTools[toolName];
const toolToHide = currentTools[toolName === "distance" ? "area" : "distance"];
toolToHide.hidden = true;
toolToShow.hidden = false;
toolToShow.start();
setActionStates();
}

When switching between 2D and 3D, the sample clones the active viewpoint, applies a latitude-based scale adjustment to better match perceived zoom between views, swaps the visible view element, and clears any measurements so results never persist across 2D/3D.