DistanceMeasurement2DViewModel

require(["esri/widgets/DistanceMeasurement2D/DistanceMeasurement2DViewModel"], function(DistanceMeasurement2DViewModel) { /* code goes here */ });
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
more detailsAccessor
Number

When the coordinate sustem is projected (other than web mercator) then distances less than this threshold will be computed planimetrically.

more details
more detailsDistanceMeasurement2DViewModel
Object

The length and geometry of the measurement polyline in meters.

more details
more detailsDistanceMeasurement2DViewModel
String

This property returns the locale specific representation of the length.

more details
more detailsDistanceMeasurement2DViewModel
String

The view model's state.

more details
more detailsDistanceMeasurement2DViewModel
SystemOrLengthUnit

Unit system (imperial, metric) or specific unit used for displaying the distance values.

more details
more detailsDistanceMeasurement2DViewModel
SystemOrLengthUnit[]

List of available units and unit systems (imperial, metric) for displaying the distance values.

more details
more detailsDistanceMeasurement2DViewModel
MapView

The view from which the widget will operate.

more details
more detailsDistanceMeasurement2DViewModel

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.

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.

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

Clears the current measurement.

more details
more detailsDistanceMeasurement2DViewModel

Starts a new measurement.

more details
more detailsDistanceMeasurement2DViewModel

Method Details

clear()
Since: ArcGIS API for JavaScript 4.16

Clears the current measurement.

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.