require(["esri/widgets/DistanceMeasurement2D/DistanceMeasurement2DViewModel"], (DistanceMeasurement2DViewModel) => { /* code goes here */ });
import DistanceMeasurement2DViewModel from "@arcgis/core/widgets/DistanceMeasurement2D/DistanceMeasurement2DViewModel.js";
esri/widgets/DistanceMeasurement2D/DistanceMeasurement2DViewModel
Provides the logic for the DistanceMeasurement2D widget.
Constructors
-
Parameterproperties Objectoptional
See the properties for a list of all the properties that may be passed into the constructor.
Property Overview
Name | Type | Summary | Class |
---|---|---|---|
The name of the class. | Accessor | ||
The length and geometry of the measurement polyline in meters. | DistanceMeasurement2DViewModel | ||
This property returns the locale specific representation of the length. | DistanceMeasurement2DViewModel | ||
The SnappingOptions for sketching. | DistanceMeasurement2DViewModel | ||
The view model's state. | DistanceMeasurement2DViewModel | ||
Unit system (imperial, metric) or specific unit used for displaying the distance values. | DistanceMeasurement2DViewModel | ||
List of available units and unit systems (imperial, metric) for displaying the distance values. | DistanceMeasurement2DViewModel | ||
The view from which the widget will operate. | DistanceMeasurement2DViewModel |
Property Details
-
The length and geometry of the measurement polyline in meters.
- Properties
-
length Number
Line length (m).
geometry PolylineMeasurement line.
Example// After creating and adding the DistanceMeasurement2D widget let measurementWidget = new DistanceMeasurement2D({ 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( "Length: ", measurement.length, "Geometry: ", measurement.geometry ); } );
-
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 widget let measurementWidget = new DistanceMeasurement2D({ view: view }); view.ui.add(measurementWidget, "top-right"); // The measurement label can be accessed from this property reactiveUtils.watch( () => measurementWidget.viewModel.measurementLabel, (label) => console.log("Label: ", label) );
-
snappingOptions
snappingOptions SnappingOptionsautocast
Since: ArcGIS Maps SDK for JavaScript 4.32DistanceMeasurement2DViewModel since 4.10, snappingOptions added at 4.32. beta -
The SnappingOptions for sketching. It supports self and feature snapping.
-
state
state Stringreadonly
-
The view model's state.
Value Description disabled not ready yet ready ready for measuring measuring measuring has started measured measuring has finished Possible Values:"disabled" |"ready" |"measuring" |"measured"
- Default Value:"disabled"
Example// To display the state of the DistanceMeasurement2D widget let measurementWidget = new DistanceMeasurement2D({ view }); reactiveUtils.watch( () => measurementWidget.viewModel.state, (state) => console.log("Current state: ", state) );
-
unit
unit 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 yards let measurementWidget = new DistanceMeasurement2D({ viewModel: { view: view, unit: "yards" } }); // To display the current measurement unit console.log('Current unit: ', measurementWidget.viewModel.unit);
-
unitOptions
unitOptions 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 console let measurementWidget = new DistanceMeasurement2D({ view: view }); console.log('All units: ', measurementWidget.viewModel.unitOptions.join(", "));
-
The view from which the widget will operate.
Example// To create DistanceMeasurement2D widget with the view property let measurementWidget = new DistanceMeasurement2D({ viewModel: { view: view } });
Method Overview
Name | Return Type | Summary | Class |
---|---|---|---|
Adds one or more handles which are to be tied to the lifecycle of the object. | Accessor | ||
Clears the current measurement. | DistanceMeasurement2DViewModel | ||
Returns true if a named group of handles exist. | Accessor | ||
Removes a group of handles owned by the object. | Accessor | ||
Starts a new measurement. | DistanceMeasurement2DViewModel |
Method Details
-
Inherited from Accessor
Since: ArcGIS Maps SDK for JavaScript 4.25Accessor since 4.0, addHandles added at 4.25. -
Adds one or more handles which are to be tied to the lifecycle of the object. The handles will be removed when the object is destroyed.
// Manually manage handles const handle = reactiveUtils.when( () => !view.updating, () => { wkidSelect.disabled = false; }, { once: true } ); this.addHandles(handle); // Destroy the object this.destroy();
ParametershandleOrHandles WatchHandle|WatchHandle[]Handles marked for removal once the object is destroyed.
groupKey *optionalKey identifying the group to which the handles should be added. All the handles in the group can later be removed with Accessor.removeHandles(). If no key is provided the handles are added to a default group.
-
Since: ArcGIS Maps SDK for JavaScript 4.16DistanceMeasurement2DViewModel since 4.10, clear added at 4.16. -
Clears the current measurement.
-
hasHandles
InheritedMethodhasHandles(groupKey){Boolean}
Inherited from AccessorSince: ArcGIS Maps SDK for JavaScript 4.25Accessor since 4.0, hasHandles added at 4.25. -
Returns true if a named group of handles exist.
ParametergroupKey *optionalA group key.
ReturnsType Description Boolean Returns true
if a named group of handles exist.Example// Remove a named group of handles if they exist. if (obj.hasHandles("watch-view-updates")) { obj.removeHandles("watch-view-updates"); }
-
Inherited from Accessor
Since: ArcGIS Maps SDK for JavaScript 4.25Accessor since 4.0, removeHandles added at 4.25. -
Removes a group of handles owned by the object.
ParametergroupKey *optionalA group key or an array or collection of group keys to remove.
Exampleobj.removeHandles(); // removes handles from default group obj.removeHandles("handle-group"); obj.removeHandles("other-handle-group");
-
Since: ArcGIS Maps SDK for JavaScript 4.16DistanceMeasurement2DViewModel since 4.10, start added at 4.16. -
Starts a new measurement.
Exampleconst distanceMeasurement2DViewModel = new DistanceMeasurement2DViewModel({ view: view, unit: "us-feet" }); await distanceMeasurement2DViewModel.start();