DirectionsViewModel

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

Provides the communication and data manipulation logic for the Directions widget.

See also:
Example:
let directions = new Directions({
  viewModel: { // autocasts as new DirectionsViewModel
    impedanceAttribute: "TravelTime" //attribute name used to specify impedance
  }
});

Constructors

new DirectionsViewModel(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
Stringmore details

An authorization string used to access a resource or service.

more detailsDirectionsViewModel
Stringmore details

The name of the class.

more detailsAccessor
GoToOverridemore details

This function provides the ability to override either the MapView goTo() or SceneView goTo() methods.

more detailsDirectionsViewModel
Stringmore details

The network attribute name to be used as the impedance attribute in the analysis.

more detailsDirectionsViewModel
Objectmore details

The most recent route result.

more detailsDirectionsViewModel
Numbermore details

The maximum number of stops allowed for routing.

more detailsDirectionsViewModel
RouteParametersmore details

Route Parameters object used to call the service.

more detailsDirectionsViewModel
Stringmore details

The URL of the REST endpoint of the Route service.

more detailsDirectionsViewModel
SimpleLineSymbolmore details

Defines the symbol used to draw the route on the map.

more detailsDirectionsViewModel
TravelModemore details

The selected travel mode.

more detailsDirectionsViewModel
Objectmore details

The Service Description object returned by the Route REST Endpoint.

more detailsDirectionsViewModel
Stringmore details

The current state of the view model.

more detailsDirectionsViewModel
Collection<Graphic>more details

An array of graphics that define the stop locations along the route.

more detailsDirectionsViewModel
Objectmore details

The default stop symbols used to display locations between the origin and final destination.

more detailsDirectionsViewModel
Objectmore details

The name of the network attribute to use for the drive time when computing directions.

more detailsDirectionsViewModel
TravelMode[]more details

Array of objects containing properties specific to either an ArcGIS service or organization's travel modes.

more detailsDirectionsViewModel
MapView|SceneViewmore details

The view from which the widget will operate.

more detailsDirectionsViewModel

Property Details

apiKey String
Since: ArcGIS API for JavaScript 4.19

An authorization string used to access a resource or service. API keys are generated and managed in the ArcGIS Developer dashboard. An API key is tied explicitly to an ArcGIS account; it is also used to monitor service usage. Setting a fine-grained API key on a specific class overrides the global API key.

declaredClass Stringreadonly inherited
Since: ArcGIS API for JavaScript 4.7

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

goToOverride GoToOverride
Since: ArcGIS API for JavaScript 4.8

This function provides the ability to override either the MapView goTo() or SceneView goTo() methods.

See also:
Example:
// The following snippet uses the Search widget but can be applied to any
// widgets that support the goToOverride property.
search.goToOverride = function(view, goToParams) {
  goToParams.options.duration = updatedDuration;
  return view.goTo(goToParams.target, goToParams.options);
};
impedanceAttribute String

The network attribute name to be used as the impedance attribute in the analysis. The default is as defined in the specific routing network layer used in your RouteTask. You can specify any attribute names listed in the Service Directory under Network Dataset -> Network Attributes as Usage Type: esriNAUTCost. You can also specify a value of none to indicate that no network attributes should be used for impedance. If you specify an empty array, it will default to the default of the service.

For example, set impedanceAttribute = "Time" for the quickest route and impedanceAttribute = "Length" for shortest drive, assuming the service has those two esriNAUTCost attributes.

For more information, see Understanding the network attribute.

lastRoute Objectreadonly

The most recent route result. Returns an object containing properties for any barriers used when generating the route, messages that may arise when solving the route, and finally an array of returned RouteResults.

Properties:
barriers Graphic[]

Array of graphics representing the point barriers. For a list of properties returned for each barrier, see the barriers help documentation.

messages Object[]

An array of messages serialized to JSON.

Specification:
description String

A descriptive message of the returned mesage.

type Number

Number indicating the message type returned from the service. This number correlates to one of the possible values listed below.

Number Value
0 informative
1 process-definition
2 process-start
3 process-stop
50 warning
100 error
101 empty
200 abort
polygonBarriers Graphic[]

Array of graphics representing the polygon barriers. For a list of properties returned for each barrier, see the barriers help documentation.

polylineBarriers Graphic[]

Array of graphics representing the polygon barriers. For a list of properties returned for each barrier, see the barriers help documentation.

routeResults RouteResult

An array of RouteResults.

Default Value:null
maxStops Number

The maximum number of stops allowed for routing.

Default Value:50
routeParameters RouteParameters

Route Parameters object used to call the service. Please refer to the RouteParameters documentation for the list of available settings.

routeServiceUrl Stringautocast

The URL of the REST endpoint of the Route service.

Default Value:"https://route-api.arcgis.com/arcgis/rest/services/World/Route/NAServer/Route_World"
routeSymbol SimpleLineSymbol

Defines the symbol used to draw the route on the map.

selectedTravelMode TravelMode

The selected travel mode. Unless specified, the Directions widget will use the first supported travel mode. For the default routeServiceUrl this is a travel mode named "Driving Time". More information can be found in the ArcGIS Online documentation.

Default Value:null
See also:
serviceDescription Objectreadonly

The Service Description object returned by the Route REST Endpoint. This object contains three properties: currentVersion, defaultTravelMode, and supportedTravelModes.

This information is useful when implementing complex logistics scenarios operating with limitations or preferences on vehicle or stop properties, for example avoiding toll roads, dealing with hazardous materials, working with stop service times, etc.

Properties:
currentVersion Number

Server version.

defaultTravelMode String

Id of the default travel mode.

supportedTravelModes TravelMode[]

Available travel modes.

Default Value:null
state Stringreadonly

The current state of the view model.

Possible Values:"disabled"|"ready"

Default Value:disabled

An array of graphics that define the stop locations along the route.

stopSymbols Object

The default stop symbols used to display locations between the origin and final destination.

Properties:
first Symbol
optional

The first stop symbol.

middle Symbol
optional

The middle stop symbol.

last Symbol
optional

The last stop symbol.

unlocated Symbol
optional

An unlocated stop symbol.

waypoint Symbol
optional

A waypoint stop symbol.

timeAttribute Objectreadonly

The name of the network attribute to use for the drive time when computing directions.

Properties:
name String

The name of the network attribute to use for the drive time when computing directions.

units String
optional

The units to use when calculating drive time for directions.

Possible Values:"feet"|"kilometers"|"meters"|"miles"|"nautical-miles"|"yards"

travelModes TravelMode[]readonly

Array of objects containing properties specific to either an ArcGIS service or organization's travel modes. More information can be found in the ArcGIS Online documentation.

The view from which the widget will operate.

Method Overview

Name Return Type Summary Class
more details

Centers the map at the specified maneuver or stop.

more detailsDirectionsViewModel
more details

Clears any highlighted route segments.

more detailsDirectionsViewModel
more details

Removes the route directions from the directions list, leaving the inputs untouched.

more detailsDirectionsViewModel
Stringmore details

Returns cost attribute name specific to a particular route service.

more detailsDirectionsViewModel
Promise<RouteResult>more details

Calculate the route to the input locations and display the list of directions.

more detailsDirectionsViewModel
more details

Highlights the specified route segment on the map.

more detailsDirectionsViewModel
Promisemore details

This method should be called to load the view model's routing resources.

more detailsDirectionsViewModel
more details

Resets the state of the ViewModel, clearing all the input stops and results in the widget and in the map.

more detailsDirectionsViewModel
more details

Zoom so that the full route is displayed within the current map extent.

more detailsDirectionsViewModel

Method Details

centerAt(stopOrManeuver)

Centers the map at the specified maneuver or stop.

Parameter:
stopOrManeuver Graphic

The stop or maneuver where the map should be centered.

clearHighlights()

Clears any highlighted route segments.

clearResults()

Removes the route directions from the directions list, leaving the inputs untouched. The route and locations persist on the map.

getCostAttribute(attributeName){String}

Returns cost attribute name specific to a particular route service. This can be used as a travel mode impedance.

Parameter:
attributeName String

The attribute name specifying the cost attribute used as an impedance.

Returns:
Type Description
String Cost attribute name specific to the route service.
getDirections(){Promise<RouteResult>}

Calculate the route to the input locations and display the list of directions.

Returns:
Type Description
Promise<RouteResult> When resolved, returns an object containing the calculated RouteResult.
highlightSegment(maneuver)

Highlights the specified route segment on the map.

Parameter:
maneuver Graphic

The route segment to highlight.

load(){Promise}

This method should be called to load the view model's routing resources.

You must first call this before using DirectionsViewModel.

Returns:
Type Description
Promise When resolved, the view model has loaded the route service metadata necessary for routing.
reset()

Resets the state of the ViewModel, clearing all the input stops and results in the widget and in the map.

zoomToRoute()

Zoom so that the full route is displayed within the current map extent.

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