Provides the communication and data manipulation logic for the Directions widget.
- See also:
const directions = new Directions({
viewModel: { // autocasts as new DirectionsViewModel
routeServiceUrl: "https://route-api.arcgis.com/arcgis/rest/services/World/Route/NAServer/Route_World"
}
});
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 | more details An authorization string used to access a resource or service. | more details | DirectionsViewModel | |
String | more details The name of the class. | more details | Accessor | |
GoToOverride | more details This function provides the ability to override either the MapView goTo() or SceneView goTo() methods. | more details | DirectionsViewModel | |
Object | more details The network attribute name to be used as the impedance attribute in the analysis. | more details | DirectionsViewModel | |
RouteLayerSolveResult | more details The most recent route result. | more details | DirectionsViewModel | |
RouteLayer | more details The RouteLayer associated with the DirectionsViewModel. | more details | DirectionsViewModel | |
Number | more details The maximum number of stops allowed for routing. | more details | DirectionsViewModel | |
RouteParameters | more details Route Parameters object used to call the service. | more details | DirectionsViewModel | |
String | more details The URL of the REST endpoint of the Route service. | more details | DirectionsViewModel | |
SimpleLineSymbol | more details Defines the symbol used to draw the route on the map. | more details | DirectionsViewModel | |
TravelMode | more details The selected travel mode. | more details | DirectionsViewModel | |
Object | more details The Service Description object returned by the Route REST Endpoint. | more details | DirectionsViewModel | |
String | more details The current state of the view model. | more details | DirectionsViewModel | |
Collection<Stop> | more details A Collection of Stops that define the stop locations along the route. | more details | DirectionsViewModel | |
RouteStopSymbols | more details The default stop symbols used to display locations between the origin and final destination. | more details | DirectionsViewModel | |
Object | more details The name of the network attribute to use for the drive time when computing directions. | more details | DirectionsViewModel | |
TravelMode[] | more details Array of objects containing properties specific to either an ArcGIS service or organization's travel modes. | more details | DirectionsViewModel | |
MapView|SceneView | more details The view from which the widget will operate. | more details | DirectionsViewModel |
Property Details
-
apiKey StringSince: 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.
By default, the following URLs will be used (unless overwritten in the app, or if using different defaults from a portal):
Geocoding URL:
https://geocode-api.arcgis.com/arcgis/rest/services/World/GeocodeServer
Routing URL:
https://route-api.arcgis.com/arcgis/rest/services/World/Route/NAServer/Route_World
-
Since: ArcGIS API for JavaScript 4.7
-
The name of the class. The declared class name is formatted as
esri.folder.className
.
-
goToOverride 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); };
-
impedanceAttribute Objectreadonly
-
The network attribute name to be used as the impedance attribute in the analysis. The value is defined in the specific routing network layer used in the route.
For more information, see Understanding the network attribute.
-
lastRoute RouteLayerSolveResultreadonly
-
The most recent route result. Returns a RouteLayerSolveResult object containing properties for barriers (if any), stops, and directions.
- Properties:
-
directionLines Collection<DirectionLine>
Collection of direction polylines associated with line segments between turns.
directionPoints Collection<DirectionPoint>Collection of direction items as points with various display information.
pointBarriers Collection<PointBarrier>Collection of point barriers.
polygonBarriers Collection<PolygonBarrier>Collection of polygon barriers.
polylineBarriers Collection<PolylineBarrier>Collection of polyline barriers.
routeInfo RouteInfoInformation about a solved route including the route's geometry and overall distance and time.
stops Collection<Stop>Collection of stops. Respresents the start, end, or midpoint of a route.
- Default Value:null
- See also:
-
layer RouteLayerSince: ArcGIS API for JavaScript 4.24
-
The RouteLayer associated with the DirectionsViewModel. The route layer contains stops and barriers and will be used to display and solve routes.
-
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 String
-
The URL of the REST endpoint of the Route service.
By default, the DirectionsViewModel will use the global routing serice (see config.routeServiceUrl).
If connected to a Portal you can use the route service advertised on the portal's helper services as demonstrated below.
- See also:
Example:// Create DirectionsViewModel using the route service advertised on the portal const portal = Portal.getDefault(); const viewModel = new DirectionsViewModel({ routeServiceUrl: portal.helperServices.route.url });
-
routeSymbol SimpleLineSymbolDeprecated since version 4.24. Use directionLines from layer instead.
-
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
, andsupportedTravelModes
.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 StringId 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
-
stops Collection<Stop>autocast
-
A Collection of Stops that define the stop locations along the route.
-
stopSymbols RouteStopSymbolsDeprecated since version 4.24. Use RouteStopSymbols from layer instead.
-
The default stop symbols used to display locations between the origin and final destination.
- Properties:
-
The first stop symbol.
The middle stop symbol.
The last stop symbol.
An unlocated stop symbol.
A waypoint stop symbol.
-
timeAttribute Objectreadonly
-
The name of the network attribute to use for the drive time when computing directions.
-
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 details | DirectionsViewModel | ||
more details Clears any highlighted route segments. | more details | DirectionsViewModel | ||
more details Removes the route directions from the directions list, leaving the inputs untouched. | more details | DirectionsViewModel | ||
Object | more details Returns the cost attribute associated with the parsed name. | more details | DirectionsViewModel | |
Promise<RouteLayerSolveResult> | more details Computes a route and directions. | more details | DirectionsViewModel | |
Promise | more details Highlights the specified network feature. | more details | DirectionsViewModel | |
more details Highlights the specified route segment on the map. | more details | DirectionsViewModel | ||
Promise | more details This method should be called to load the view model's routing resources. | more details | DirectionsViewModel | |
more details Resets the state of the ViewModel, clearing all the input stops and results in the widget and in the map. | more details | DirectionsViewModel | ||
Promise<PortalItem> | more details Saves the RouteLayer associated with the view model. | more details | DirectionsViewModel | |
Promise<PortalItem> | more details Saves the RouteLayer associated with the view model as a new portal item. | more details | DirectionsViewModel | |
more details Zoom so that the full route is displayed within the current map extent. | 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){Object}
-
Returns the cost attribute associated with the parsed name.
Parameter:attributeName StringThe attribute name specifying the cost attribute used as an impedance.
Returns:Type Description Object The cost attribute associated with the passed name. Property Type Description name string Name of the impedance network attribute. units string Units of this network attribute.
-
getDirections(){Promise<RouteLayerSolveResult>}
-
Computes a route and directions. If successful, results will be assigned to lastRoute and returned in a resolving promise. If a view is assigned, it will zoom to the extent of the route.
Returns:Type Description Promise<RouteLayerSolveResult> When resolved, returns a RouteLayerSolveResult.
-
highlight(networkFeature){Promise}Since: ArcGIS API for JavaScript 4.24
-
Highlights the specified network feature.
Parameter:networkFeature DirectionLine|DirectionPoint|PointBarrier|PolygonBarrier|PolylineBarrier|RouteInfo|StopThe network feature to highlight.
Returns:Type Description Promise Resolves when the highlight has been completed.
-
highlightSegment(maneuver)Deprecated since version 4.24. Use highlight instead.
-
Highlights the specified route segment on the map.
Parameter:maneuver GraphicThe route segment to highlight.
-
load(){Promise}
-
This method should be called to load the view model's routing resources.
This method downloads service metadata from the assigned routing service. Call this method before accessing properties on the view model or whenever the routeServiceUrl changes.
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.
-
save(){Promise<PortalItem>}Since: ArcGIS API for JavaScript 4.24
-
Saves the RouteLayer associated with the view model. This method will update the portal-item associated with layer.
Returns:Type Description Promise<PortalItem> When resolved, returns a PortalItem. - See also:
-
saveAs(portalItem, options){Promise<PortalItem>}Since: ArcGIS API for JavaScript 4.24
-
Saves the RouteLayer associated with the view model as a new portal item.
Parameters:portalItem Promise<PortalItem>The new portal item to which the layer will be saved.
options ObjectoptionalSave options. Currently, there is only one property that can be set, which is
folder
.Specification:folder PortalFolderoptionalThe folder in which to save the item.
Returns:Type Description Promise<PortalItem> Saved portal item. - See also:
-
zoomToRoute()
-
Zoom so that the full route is displayed within the current map extent.