Skip To ContentArcGIS for DevelopersSign In Dashboard

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.
NameTypeSummaryClass
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
String

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

more details
more detailsDistanceMeasurement2DViewModel
String[]

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

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

ValueDescription
disablednot ready yet
readyready for measuring
measuringmeasuring has started
measuredmeasuring has finished

Possible Values:"disabled"|"ready"|"measuring"|"measured"

Default Value:disabled
Example:
// To display the state of the DistanceMeasurement2D widget
var measurementWidget = new DistanceMeasurement2D({
  view: view
});
measurementWidget.watch("viewModel.state", function(state){
  console.log("Current state: ", state);
});
unit String

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

Possible Values:"metric"|"imperial"|"inches"|"feet"|"us-feet"|"yards"|"miles"|"nautical-miles"|"meters"|"kilometers"

Example:
// To create the DistanceMeasurement2D widget that displays distance in yards
var measurementWidget = new DistanceMeasurement2D({
  viewModel: {
    view: view,
    unit: "yards"
  }
});

// To display the current measurement unit
console.log('Current unit: ', measurementWidget.viewModel.unit);
unitOptions String[]

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

Possible Values:"metric"|"imperial"|"inches"|"feet"|"us-feet"|"yards"|"miles"|"nautical-miles"|"meters"|"kilometers"

Example:
// To display the available units to the console
var 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
var measurementWidget = new DistanceMeasurement2D({
  viewModel: {
    view: view
  }
});

Method Overview

NameReturn TypeSummaryClass

Clears the current measurement.

more details
more detailsDistanceMeasurement2DViewModel

Starts a new measurement.

more details
more detailsDistanceMeasurement2DViewModel

Method Details

clearMeasurement()

Clears the current measurement.

newMeasurement()

Starts a new measurement.

API Reference search results

NameTypeModule
Loading...