import DistanceMeasurement2DViewModel from "@arcgis/core/widgets/DistanceMeasurement2D/DistanceMeasurement2DViewModel.js";const DistanceMeasurement2DViewModel = await $arcgis.import("@arcgis/core/widgets/DistanceMeasurement2D/DistanceMeasurement2DViewModel.js");- Inheritance:
- DistanceMeasurement2DViewModel→
Accessor
- Since
- ArcGIS Maps SDK for JavaScript 4.10
Provides the logic for the DistanceMeasurement2D 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
- LinearMeasurement | null | undefined
The length and geometry of the measurement polyline in meters.
Example
// After creating and adding the DistanceMeasurement2D widgetlet measurementWidget = new DistanceMeasurement2D({ 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( "Length: ", measurement.length, "Geometry: ", measurement.geometry ); }); measurementLabel
This property returns the locale specific representation of the length. Lengths are rounded to two decimal places. Lengths are sourced from the measurement property (in meters) and converted to the user defined units or system.
Example
// After creating and adding the DistanceMeasurement2D widgetlet measurementWidget = new DistanceMeasurement2D({ view: view});view.ui.add(measurementWidget, "top-right");
// The measurement label can be accessed from this propertyreactiveUtils.watch( () => measurementWidget.viewModel.measurementLabel, (label) => console.log("Label: ", label)); 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 view model'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 DistanceMeasurement2D widgetlet measurementWidget = new DistanceMeasurement2D({ view });
reactiveUtils.watch( () => measurementWidget.viewModel.state, (state) => console.log("Current state: ", state)); unit
- Type
- SystemOrLengthUnit
Unit system (imperial, metric) or specific unit used for displaying the distance values. Possible values are listed in unitOptions.
Example
// To create the DistanceMeasurement2D widget that displays distance in yardslet measurementWidget = new DistanceMeasurement2D({ viewModel: { view: view, unit: "yards" }});
// To display the current measurement unitconsole.log('Current unit: ', measurementWidget.viewModel.unit); unitOptions
- Type
- SystemOrLengthUnit[]
List of available units and unit systems (imperial, metric) for displaying the distance values.
By default, the following units are included: metric, imperial, inches, feet, us-feet, yards, miles, nautical-miles, meters, kilometers.
Possible unit values can only be a subset of this list.
Example
// To display the available units to the consolelet measurementWidget = new DistanceMeasurement2D({ 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