MeasurementViewModel

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

Provides the logic for the Measurement widget.

See also

Constructors

MeasurementViewModel

Constructor
new MeasurementViewModel(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

Specifies the current measurement tool to display.

MeasurementViewModel

View model of the active measurement widget.

MeasurementViewModel

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

MeasurementViewModel

The name of the class.

Accessor

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

MeasurementViewModel

The ViewModel's state.

MeasurementViewModel

A reference to the MapView or SceneView.

MeasurementViewModel

Property Details

activeTool

Property
activeTool String

Specifies the current measurement tool to display. Setting its value to area activates the area measurement tool and it works for both MapView and SceneView. To measure distance in a MapView set the property to distance and in a SceneView set it to direct-line. If this property is not set, the widget will not be displayed.

Possible Values:"area" |"distance" |"direct-line"

Default Value:null
Example
// To create the Measurement widget with SceneView's linear measurement widget active.
let measurement = new Measurement({
  viewModel: {
    view: view,
    activeTool: "direct-line"
  }
});

View model of the active measurement widget.

Example
// Print the active view model to the console.
let measurement = new Measurement({
  viewModel: {
    areaUnit: "square-us-feet",
    view: view,
    activeTool: "area"
  }
});
console.log("Active ViewModel: ", measurement.viewModel.activeViewModel);

areaUnit

Property
areaUnit SystemOrAreaUnit

Unit system (imperial, metric) or specific unit used for displaying the area values. Possible values are: metric, imperial, square-inches, square-feet, square-us-feet, square-yards, square-miles, square-meters, square-kilometers, acres, ares, hectares.

Example
// To create the Measurement widget that displays area in square US feet
let measurement = new Measurement({
  viewModel: {
    areaUnit: "square-us-feet",
    view: view,
    activeTool: "area"
  }
});

// To display the current measurement unit for area
console.log("Current unit: ", measurement.viewModel.areaUnit);

declaredClass

Inherited
Property
declaredClass Stringreadonly
Inherited from Accessor

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

linearUnit

Property
linearUnit SystemOrLengthUnit

Unit system (imperial, metric) or specific unit used for displaying the distance values. Possible values are: metric, imperial, inches, feet, us-feet, yards, miles, nautical-miles, meters, kilometers.

Example
// To create the Measurement widget that displays distance in yards
let measurement = new Measurement({
  viewModel: {
    linearUnit: "yards",
    view: view,
    activeTool: "distance"
  }
});

// To display the current measurement unit for distance
console.log('Current unit: ', measurement.viewModel.linearUnit);

state

Property
state Stringreadonly

The ViewModel'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 AreaMeasurement2D widget
let measurement = new Measurement({
  view: view,
  activeTool: "area"
});
reactiveUtils.watch(
  () => measurement.viewModel.state,
  (state) => console.log("Current state: ", state)
);

view

Property
view MapView |SceneView

A reference to the MapView or SceneView.

Example
// Add the measurement widget to the upper right hand corner.
const measurement = new Measurement({
  viewModel: {
    view: view,
    activeTool = "distance";
  }
});
view.ui.add(measurement, "top-right");

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

Returns true if a named group of handles exist.

Accessor

Removes a group of handles owned by the object.

Accessor

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.

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");

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