DistanceMeasurement2DViewModel

AMD: require(["esri/widgets/DistanceMeasurement2D/DistanceMeasurement2DViewModel"], (DistanceMeasurement2DViewModel) => { /* code goes here */ });
ESM: import DistanceMeasurement2DViewModel from "@arcgis/core/widgets/DistanceMeasurement2D/DistanceMeasurement2DViewModel";
Class: esri/widgets/DistanceMeasurement2D/DistanceMeasurement2DViewModel
Inheritance: DistanceMeasurement2DViewModel Accessor
Since: ArcGIS API for JavaScript 4.10

Provides the logic for the DistanceMeasurement2D widget.

See also

Constructors

new DistanceMeasurement2DViewModel(properties)
Parameter
properties Object
optional

See the properties for a list of all the properties that may be passed into the constructor.

Property Overview

Any properties can be set, retrieved or listened to. See the Working with Properties topic.
Show inherited properties Hide inherited properties
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

declaredClass Stringreadonly inherited

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 Polyline

Measurement 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
measurementWidget.watch("viewModel.measurement", function(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
measurementWidget.watch("viewModel.measurementLabel", function(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: view
});
measurementWidget.watch("viewModel.state", function(state){
  console.log("Current state: ", state);
});

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

Show inherited methods Hide inherited methods
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)inherited
Since: ArcGIS API 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 }
);

// Handle gets removed when the object is destroyed.
this.addHandles(handle);
Parameters
handleOrHandles WatchHandle|WatchHandle[]

Handles marked for removal once the object is destroyed.

groupKey *
optional

Key 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 API for JavaScript 4.16

Clears the current measurement.

hasHandles(groupKey){Boolean}inherited
Since: ArcGIS API for JavaScript 4.25

Returns true if a named group of handles exist.

Parameter
groupKey *
optional

A group key.

Returns
Type 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)inherited
Since: ArcGIS API for JavaScript 4.25

Removes a group of handles owned by the object.

Parameter
groupKey *
optional

A group key or an array or collection of group keys to remove.

Example
obj.removeHandles(); // removes handles from default group

obj.removeHandles("handle-group");
obj.removeHandles("other-handle-group");
start()
Since: ArcGIS API for JavaScript 4.16

Starts a new measurement.

Example
const distanceMeasurement2DViewModel = new DistanceMeasurement2DViewModel({
  view: view,
  unit: "us-feet"
});

await distanceMeasurement2DViewModel.start();

Your browser is no longer supported. Please upgrade your browser for the best experience. See our browser deprecation post for more details.