DistanceMeasurement2DViewModel

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

Provides the logic for the DistanceMeasurement2D widget.

See also

Constructors

DistanceMeasurement2DViewModel

Constructor
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

The name of the class.

Accessor

Threshold (in meters) which determines the method for computing and displaying distances in non-Web Mercator projected coordinate systems (PCS).

DistanceMeasurement2DViewModel

The length and geometry of the measurement polyline in meters.

DistanceMeasurement2DViewModel

This property returns the locale specific representation of the length.

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

declaredClass

Inherited
Property
declaredClass Stringreadonly
Inherited from Accessor

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

geodesicDistanceThreshold

Property
geodesicDistanceThreshold Number
Deprecated since version 4.29.

Threshold (in meters) which determines the method for computing and displaying distances in non-Web Mercator projected coordinate systems (PCS).

  • Below this threshold, distances are computed in a Euclidean manner (in their respective PCS).
  • Above this threshold, distances are computed geodetically.

If the threshold is omitted (default), distances are always computed in a Euclidean manner.

This property is ignored if the map’s spatial reference is a geographic coordinate system (GCS) or Web Mercator. Meaning that distances are always computed geodetically.

Default Value:null
Example
// To set the threshold at 10 km
let measurementWidget = new DistanceMeasurement2D({
  viewModel: {
    view: view,
    geodesicDistanceThreshold: 10000
  }
});

measurement

Property
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
reactiveUtils.watch(
  () => measurementWidget.viewModel.measurement,
  (measurement) => {
    console.log(
      "Length: ", measurement.length,
      "Geometry: ", measurement.geometry
    );
  }
);

measurementLabel

Property
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

Property
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

Property
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

Property
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

Property
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.

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

addHandles

Inherited
Method
addHandles(handleOrHandles, groupKey)
Inherited from Accessor
Since: ArcGIS Maps SDK for JavaScript 4.25 Accessor 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();
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

Method
clear()
Since: ArcGIS Maps SDK for JavaScript 4.16 DistanceMeasurement2DViewModel since 4.10, clear added at 4.16.

Clears the current measurement.

hasHandles

Inherited
Method
hasHandles(groupKey){Boolean}
Inherited from Accessor
Since: ArcGIS Maps SDK for JavaScript 4.25 Accessor since 4.0, hasHandles added at 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

Inherited
Method
removeHandles(groupKey)
Inherited from Accessor
Since: ArcGIS Maps SDK for JavaScript 4.25 Accessor since 4.0, removeHandles added at 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

Method
start()
Since: ArcGIS Maps SDK for JavaScript 4.16 DistanceMeasurement2DViewModel since 4.10, start added at 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.