Area measurement analysis object

This sample shows how to display area measurements for polygons that are selected by the user. Create and add an AreaMeasurementAnalysis Object to the sceneview.analyses. Add a click event listener on the view. If the user clicked on a parcel polygon, add the polygon to the geometry property of the AreaMeasurementAnalysis Object.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
// create a AreaMeasurementAnalysis object and add it to the AnalysisLayer
const areaMeasurementAnalysis = new AreaMeasurementAnalysis();
view.analyses.add(areaMeasurementAnalysis);

view.when(() => {
  const hitTestLayers = view.map.layers.filter((layer) => layer.title === "Parcels");
  view.on("click", async (event) => {
    // remove the current measured geometry from the layer when the user clicks on the map
    areaMeasurementAnalysis.geometry = null;
    // get results only from the "Parcels" layer
    const hitTestResult = await view.hitTest(event, { include: hitTestLayers });
    if (hitTestResult.results.length > 0) {
      const geometry = hitTestResult.results[0].graphic.geometry;
      // pass the polygon geometry to the areaMeasurementAnalysis to display a new measurement
      areaMeasurementAnalysis.geometry = geometry;
    }
  });
});

For using the other analysis object see also the sample Analysis objects.

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

The developer dashboard has moved

You can no longer sign into this site. Go to your ArcGIS portal or the ArcGIS Location Platform dashboard to perform management tasks.

Your ArcGIS portal

Create, manage, and access API keys and OAuth 2.0 developer credentials, hosted layers, and data services.

Your ArcGIS Location Platform dashboard

Manage billing, monitor service usage, and access additional resources.

Learn more about these changes in the What's new in Esri Developers June 2024 blog post.

Close