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
-
new DistanceMeasurement2DViewModel(properties)
-
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 |
---|---|---|---|
String | The name of the class. more details | Accessor | |
Number | When the coordinate sustem is projected (other than web mercator) then distances less than this threshold will be computed planimetrically. more details | DistanceMeasurement2DViewModel | |
Object | The length and geometry of the measurement polyline in meters. more details | DistanceMeasurement2DViewModel | |
String | This property returns the locale specific representation of the length. more details | DistanceMeasurement2DViewModel | |
String | The view model's state. more details | DistanceMeasurement2DViewModel | |
SystemOrLengthUnit | Unit system (imperial, metric) or specific unit used for displaying the distance values. more details | DistanceMeasurement2DViewModel | |
SystemOrLengthUnit[] | List of available units and unit systems (imperial, metric) for displaying the distance values. more details | DistanceMeasurement2DViewModel | |
MapView | The view from which the widget will operate. more details | DistanceMeasurement2DViewModel |
Property Details
-
The name of the class. The declared class name is formatted as
esri.folder.className
.
-
geodesicDistanceThreshold Number
-
When the coordinate sustem is projected (other than web mercator) then distances less than this threshold will be computed planimetrically. Otherwise distances will be computed geodetically.
- Default Value:100000
Example// To set the threshold at 10 km let measurementWidget = new DistanceMeasurement2D({ viewModel: { view: view, geodesicDistanceThreshold: 10000 } });
-
measurement Objectreadonly
-
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 ); } );
-
measurementLabel Stringreadonly
-
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) );
-
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 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 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(", "));
-
view MapView
-
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. more details | Accessor | ||
Clears the current measurement. more details | DistanceMeasurement2DViewModel | ||
Boolean | Returns true if a named group of handles exist. more details | Accessor | |
Removes a group of handles owned by the object. more details | Accessor | ||
Starts a new measurement. more details | DistanceMeasurement2DViewModel |
Method Details
-
addHandles(handleOrHandles, groupKey)inheritedSince: ArcGIS Maps SDK for JavaScript 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.
-
clear()Since: ArcGIS Maps SDK for JavaScript 4.16
-
Clears the current measurement.
-
Since: ArcGIS Maps SDK for JavaScript 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"); }
-
removeHandles(groupKey)inheritedSince: ArcGIS Maps SDK for JavaScript 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");
-
start()Since: ArcGIS Maps SDK for JavaScript 4.16
-
Starts a new measurement.
Exampleconst distanceMeasurement2DViewModel = new DistanceMeasurement2DViewModel({ view: view, unit: "us-feet" }); await distanceMeasurement2DViewModel.start();