DirectionsViewModel
require(["esri/widgets/Directions/DirectionsViewModel"], function(DirectionsVM) { /* code goes here */ });
esri/widgets/Directions/DirectionsViewModel
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:
var directions = new Directions({
viewModel: { // autocasts as new DirectionsViewModel
impedanceAttribute: "TravelTime" //attribute name used to specify impedance
}
});
Constructors
- new DirectionsViewModel(properties)
- Parameter:properties Objectoptional
See the properties for a list of all the properties that may be passed into the constructor.
Property Overview
Name | Type | Summary | Class | |
---|---|---|---|---|
String | The name of the class. more details | more details | Accessor | |
GoToOverride | This function provides the ability to override either the MapView goTo() or SceneView goTo() methods. more details | more details | DirectionsViewModel | |
String | The network attribute name to be used as the impedance attribute in the analysis. more details | more details | DirectionsViewModel | |
Object | The most recent route result. more details | more details | DirectionsViewModel | |
Number | The maximum number of stops allowed for routing. more details | more details | DirectionsViewModel | |
RouteParameters | Route Parameters object used to call the service. more details | more details | DirectionsViewModel | |
String | The URL of the REST endpoint of the Route service. more details | more details | DirectionsViewModel | |
SimpleLineSymbol | Defines the symbol used to draw the route on the map. more details | more details | DirectionsViewModel | |
TravelMode | The selected travel mode. more details | more details | DirectionsViewModel | |
Object | The Service Description object returned by the Route REST Endpoint. more details | more details | DirectionsViewModel | |
String | The current state of the view model. more details | more details | DirectionsViewModel | |
Collection<Graphic> | An array of graphics that define the stop locations along the route. more details | more details | DirectionsViewModel | |
Object | The default stop symbols used to display locations between the origin and final destination. more details | more details | DirectionsViewModel | |
Object | The name of the network attribute to use for the drive time when computing directions. more details | more details | DirectionsViewModel | |
TravelMode[] | Array of objects containing properties specific to either an ArcGIS service or organization's travel modes. more details | more details | DirectionsViewModel | |
MapView | SceneView | The view from which the widget will operate. more details | more details | DirectionsViewModel |
Property Details
- Since: ArcGIS API for JavaScript 4.7
The name of the class. The declared class name is formatted as
esri.folder.className
.
- goToOverrideSince: ArcGIS API for JavaScript 4.8
This function provides the ability to override either the MapView goTo() or SceneView goTo() methods.
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
asUsage Type: esriNAUTCost
. You can also specify a value ofnone
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 andimpedanceAttribute = "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 NumberNumber 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 RouteResultAn 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.
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.
- selectedTravelModereadonly
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.
id StringThe unique identifier specific for this travel mode.
impedanceAttributeName StringThe cost attribute on which to optimize the analysis. For example
Miles
,Minutes
,Travel Time
,Kilometers
,TimeAt1KPH
,WalkTime
, andTruckTravelTime
. 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 StringName 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 StringThe time-based cost attribute for reporting directions. For example,
Minutes
,Travel Time
,TimeAt1KPH
,WalkTime
, andTruckTravelTime
. - 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
- stopsCollection<Graphic>
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.
- timeAttributeObject
The name of the network attribute to use for the drive time when computing directions.
- travelModesreadonly
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 | |
---|---|---|---|---|
Centers the map at the specified maneuver or stop. more details | more details | DirectionsViewModel | ||
Clears any highlighted route segments. more details | more details | DirectionsViewModel | ||
Removes the route directions from the directions list, leaving the inputs untouched. more details | more details | DirectionsViewModel | ||
String | Returns cost attribute name specific to a particular route service. more details | more details | DirectionsViewModel | |
Promise<RouteResult> | Calculate the route to the input locations and display the list of directions. more details | more details | DirectionsViewModel | |
Highlights the specified route segment on the map. more details | more details | DirectionsViewModel | ||
Resets the state of the ViewModel, clearing off all the input stops, and results in the widget. more details | more details | DirectionsViewModel | ||
Zoom so that the full route is displayed within the current map extent. more details | more details | DirectionsViewModel |
Method Details
- centerAt(stopOrManeuver)
Centers the map at the specified maneuver or stop.
Parameter:stopOrManeuver GraphicThe 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 StringThe 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 GraphicThe 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:
- optionaldescription String
The description explaining the selected travel mode. A listing of these descriptions can be found in the ArcGIS Online documentation.
optionalid StringThe unique identifier specific for this travel mode.
optionalimpedanceAttributeName StringThe cost attribute on which to optimize the analysis. For example
Miles
,Minutes
,Travel Time
,Kilometers
,TimeAt1KPH
,WalkTime
, andTruckTravelTime
. 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.optionalname StringName 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.
optionaltimeAttributeName StringThe time-based cost attribute for reporting directions. For example,
Minutes
,Travel Time
,TimeAt1KPH
,WalkTime
, andTruckTravelTime
.