require(["esri/widgets/Directions/DirectionsViewModel"], function(DirectionsVM) { /* code goes here */ });
Class: esri/widgets/Directions/DirectionsViewModel
Inheritance: DirectionsViewModel Accessor
Since: ArcGIS API for JavaScript 4.6
beta

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

Known Limitations

The Directions widget is currently in its beta release. With this said, it should be noted that it is not yet at full parity with the functionality provided in the 3.x version of the Directions widget and is subject to change.

See also:
Example:
var 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.
NameTypeSummaryClass
String

The name of the class.

more details
more detailsAccessor
GoToOverride

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

more details
more detailsDirectionsViewModel
String

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

more details
more detailsDirectionsViewModel
Object

The most recent route result.

more details
more detailsDirectionsViewModel
Number

The maximum number of stops allowed for routing.

more details
more detailsDirectionsViewModel
RouteParameters

Route Parameters object used to call the service.

more details
more detailsDirectionsViewModel
String

The URL of the REST endpoint of the Route service.

more details
more detailsDirectionsViewModel
SimpleLineSymbol

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

more details
more detailsDirectionsViewModel
TravelMode

The selected travel mode.

more details
more detailsDirectionsViewModel
Object

The Service Description object returned by the Route REST Endpoint.

more details
more detailsDirectionsViewModel
String

The current state of the view model.

more details
more detailsDirectionsViewModel
Collection<Graphic>

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

more details
more detailsDirectionsViewModel
Object

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

more details
more detailsDirectionsViewModel
Object

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

more details
more detailsDirectionsViewModel
TravelMode[]

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

more details
more detailsDirectionsViewModel
MapView | SceneView

The view from which the widget will operate.

more details
more detailsDirectionsViewModel

Property Details

declaredClassStringreadonly inherited
Since: ArcGIS API for JavaScript 4.7

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

goToOverrideGoToOverride
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);
};
impedanceAttributeString

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.

lastRouteObjectreadonly

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.

NumberValue
0informative
1process-definition
2process-start
3process-stop
50warning
100error
101empty
200abort
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
maxStopsNumber

The maximum number of stops allowed for routing.

Default Value:50
routeParametersRouteParameters

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

routeServiceUrlStringautocast

The URL of the REST endpoint of the Route service.

Default Value:"https://route.arcgis.com/arcgis/rest/services/World/Route/NAServer/Route_World"
routeSymbolSimpleLineSymbol

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

selectedTravelModeTravelModereadonly

The selected travel mode. More information can be found in the ArcGIS Online documentation.

Properties:
description String

The description explaining the selected travel mode. A listing of these descriptions can be found in the ArcGIS Online documentation.

The unique identifier specific for this travel mode.

impedanceAttributeName String

The cost attribute on which to optimize the analysis. For example Miles, Minutes, Travel Time, Kilometers, TimeAt1KPH, WalkTime, and TruckTravelTime. Take note that attribute names are specific to the network dataset. They may be different if using another Network Analysis service besides the one hosted via ArcGIS Online.

name String

Name of the travel mode. Users of ArcGIS Online or ArcGIS Enterprise can define custom travel modes inside their Organization settings. Authors of stand alone Network Analysis Services can define their own travel modes inside a network dataset.

timeAttributeName String

The time-based cost attribute for reporting directions. For example, Minutes, Travel Time, TimeAt1KPH, WalkTime, and TruckTravelTime.

Default Value:null | 'Driving Time'
serviceDescriptionObjectreadonly

The Service Description object returned by the Route REST Endpoint. This object contains service specific details like available Cost attributes, supported Restrictions, default Attribute Parameter Values, Service Limits (like maximum input stop count), default Impedance Attribute, etc. 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.

Default Value:null
stateStringreadonly

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.

stopSymbolsObject

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.

timeAttributeObject

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

travelModesTravelMode[]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

NameReturn TypeSummaryClass

Centers the map at the specified maneuver or stop.

more details
more detailsDirectionsViewModel

Clears any highlighted route segments.

more details
more detailsDirectionsViewModel

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

more details
more detailsDirectionsViewModel
String

Returns cost attribute name specific to a particular route service.

more details
more detailsDirectionsViewModel
Promise<RouteResult>

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

more details
more detailsDirectionsViewModel

Highlights the specified route segment on the map.

more details
more detailsDirectionsViewModel

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

more details
more detailsDirectionsViewModel

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

more details
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:
TypeDescription
StringCost attribute name specific to the route service.
getDirections(){Promise<RouteResult>}

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

Returns:
TypeDescription
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.

reset()

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

zoomToRoute()

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

Type Definitions

TravelMode

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.

Properties:
description String
optional

The description explaining the selected travel mode. A listing of these descriptions can be found in the ArcGIS Online documentation.

optional

The unique identifier specific for this travel mode.

impedanceAttributeName String
optional

The cost attribute on which to optimize the analysis. For example Miles, Minutes, Travel Time, Kilometers, TimeAt1KPH, WalkTime, and TruckTravelTime. Take note that attribute names are specific to the network dataset. They may be different if using another Network Analysis service besides the one hosted via ArcGIS Online.

name String
optional

Name of the travel mode. Users of ArcGIS Online or ArcGIS Enterprise can define custom travel modes inside their Organization settings. Authors of stand alone Network Analysis Services can define their own travel modes inside a network dataset.

timeAttributeName String
optional

The time-based cost attribute for reporting directions. For example, Minutes, Travel Time, TimeAt1KPH, WalkTime, and TruckTravelTime.

API Reference search results

NameTypeModule
Loading...