import AreaMeasurement2DViewModel from "@arcgis/core/widgets/AreaMeasurement2D/AreaMeasurement2DViewModel.js";const AreaMeasurement2DViewModel = await $arcgis.import("@arcgis/core/widgets/AreaMeasurement2D/AreaMeasurement2DViewModel.js");- Inheritance:
- AreaMeasurement2DViewModel→
Accessor
- Since
- ArcGIS Maps SDK for JavaScript 4.10
Provides the logic for the AreaMeasurement2D widget and component.
Constructors
Constructor
Parameters
| Parameter | Type | Description | Required |
|---|---|---|---|
| properties | | |
Properties
| Property | Type | Class |
|---|---|---|
declaredClass readonly inherited | ||
measurement readonly | | |
measurementLabel readonly | | |
| | ||
state readonly | | |
| | ||
| | ||
| |
measurement
- Type
- AreaMeasurement | null | undefined
The area and perimeter of the measurement polygon in square meters and meters respectively.
Example
// After creating and adding the AreaMeasurement2D widgetlet measurementWidget = new AreaMeasurement2D({ view: view});view.ui.add(measurementWidget, "top-right");
// Raw measurements (in meters) can be accessed from this propertyreactiveUtils.watch(() => measurementWidget.viewModel.measurement, (measurement) => { console.log( "Area: ", measurement.area, "Perimeter: ", measurement.perimeter ); }); measurementLabel
- Type
- AreaMeasurementLabel | null | undefined
This property returns the locale specific representation of the area and perimeter. Areas and perimeters are rounded to two decimal places. Areas are sourced from the measurement property (in square meters) and converted to the user defined units/system.
Example
// After creating and adding the AreaMeasurement2D widgetlet measurementWidget = new AreaMeasurement2D({ view: view});view.ui.add(measurementWidget, "top-right");
// Measurement labels can be accessed from this propertyreactiveUtils.watch(() => measurementWidget.viewModel.measurementLabel, (label) => { console.log( "Area: ", label.area, "Perimeter: ", label.perimeter ); }); snappingOptions
- Type
- SnappingOptions
- Since
- ArcGIS Maps SDK for JavaScript 4.32
The SnappingOptions for sketching. It supports self and feature snapping.
state
- Type
- MeasurementState
The ViewModel's state.
| Value | Description |
|---|---|
| disabled | not ready yet |
| ready | ready for measuring |
| measuring | measuring has started |
| measured | measuring has finished |
- Default value
- "disabled"
Example
// To display the state of the AreaMeasurement2D widgetlet measurementWidget = new AreaMeasurement2D({ view: view});reactiveUtils.watch( () => measurementWidget.viewModel.state, (state) => console.log("Current state: ", state)); unit
- Type
- SystemOrAreaUnit
Unit system (imperial, metric) or specific unit used for displaying the area values. Possible values are listed in unitOptions.
Example
// To create the AreaMeasurement2D widget that displays area in square US feetlet measurementWidget = new AreaMeasurement2D({ viewModel: { view: view, unit: "square-us-feet" }});
// To display the current measurement unitconsole.log('Current unit: ', measurementWidget.viewModel.unit); unitOptions
- Type
- SystemOrAreaUnit[]
List of available units and unit systems (imperial, metric) for displaying the area values.
By default, the following units are included: metric, imperial, square-inches, square-feet, square-us-feet, square-yards, square-miles, square-meters, square-kilometers, acres, ares, hectares.
Possible unit values can only be a subset of this list.
Example
// To display the available units to the consolelet measurementWidget = new AreaMeasurement2D({ view: view});console.log('All units: ', measurementWidget.viewModel.unitOptions.join(", "));Methods
clear
- Signature
-
clear (): void
- Since
- ArcGIS Maps SDK for JavaScript 4.16
Clears the current measurement.
- Returns
- void