Skip to content
import AreaMeasurement2DViewModel from "@arcgis/core/widgets/AreaMeasurement2D/AreaMeasurement2DViewModel.js";
Inheritance:
AreaMeasurement2DViewModelAccessor
Since
ArcGIS Maps SDK for JavaScript 4.10

Provides the logic for the AreaMeasurement2D widget and component.

See also

Constructors

Constructor

Constructor
Parameters
ParameterTypeDescriptionRequired
properties
See the properties table for a list of all the properties that may be passed into the constructor.

Properties

Any properties can be set, retrieved or listened to. See the Watch for changes topic.

declaredClass

readonlyinherited Property
Type
string
Inherited from: Accessor

The name of the class. The declared class name is formatted as esri.folder.className.

measurement

readonly Property
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 widget
let measurementWidget = new AreaMeasurement2D({
view: view
});
view.ui.add(measurementWidget, "top-right");
// Raw measurements (in meters) can be accessed from this property
reactiveUtils.watch(
() => measurementWidget.viewModel.measurement,
(measurement) => {
console.log(
"Area: ", measurement.area,
"Perimeter: ", measurement.perimeter
);
}
);

measurementLabel

readonly Property
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 widget
let measurementWidget = new AreaMeasurement2D({
view: view
});
view.ui.add(measurementWidget, "top-right");
// Measurement labels can be accessed from this property
reactiveUtils.watch(
() => measurementWidget.viewModel.measurementLabel,
(label) => {
console.log(
"Area: ", label.area,
"Perimeter: ", label.perimeter
);
}
);

snappingOptions

autocast Property
Type
SnappingOptions
Since
ArcGIS Maps SDK for JavaScript 4.32
beta

The SnappingOptions for sketching. It supports self and feature snapping.

state

readonly Property
Type
MeasurementState

The ViewModel's state.

ValueDescription
disablednot ready yet
readyready for measuring
measuringmeasuring has started
measuredmeasuring has finished
Default value
"disabled"
Example
// To display the state of the AreaMeasurement2D widget
let measurementWidget = new AreaMeasurement2D({
view: view
});
reactiveUtils.watch(
() => measurementWidget.viewModel.state,
(state) => console.log("Current state: ", state)
);

unit

autocast Property
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 feet
let measurementWidget = new AreaMeasurement2D({
viewModel: {
view: view,
unit: "square-us-feet"
}
});
// To display the current measurement unit
console.log('Current unit: ', measurementWidget.viewModel.unit);

unitOptions

autocast Property
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 console
let measurementWidget = new AreaMeasurement2D({
view: view
});
console.log('All units: ', measurementWidget.viewModel.unitOptions.join(", "));

view

Property
Type
MapView | null | undefined

The view from which the widget will operate.

Example
// To create the AreaMeasurement2D widget with the view property
let measurementWidget = new AreaMeasurement2D({
viewModel: {
view: view
}
});

Methods

MethodSignatureClass
clear(): void
start(): Promise<void>

clear

Method
Signature
clear (): void
Since
ArcGIS Maps SDK for JavaScript 4.16

Clears the current measurement.

Returns
void

start

Method
Signature
start (): Promise<void>
Since
ArcGIS Maps SDK for JavaScript 4.16

Starts a new measurement.

Returns
Promise<void>
Example
const areaMeasurement2DViewModel = new AreaMeasurement2DViewModel({
view: view,
unit: "square-yards"
});
await areaMeasurement2DViewModel.start();