Class: RouteTaskE-mail This TopicPrintable VersionGive Us Feedback

Description

Class added v1.4.
dojo.require("esri.tasks.route");

Solves a route on a route layer resource in a Network Analyst service exposed by the ArcGIS Server REST API. For more information on using RouteTask, see An overview of routing with the ArcGIS JavaScript API and Working with the RouteTask.

Samples

Search for samples that use this class.  

Class hierarchy

esri.tasks.RouteTask

Constructor

Constructor Description
esri.tasks.RouteTask(url) Creates a new RouteTask object.

Properties

Property Type Description
url String URL to the ArcGIS Server REST resource that represents a network analysis service. To obtain the URL, use Services Directory.

Methods

Method Return Value Description
solve(params, callback?, errback?) dojo.Deferred Solves the route against the route layer with the route parameters.

Events

Event Description
onError(error) Fires when an error occurs when executing the task.
onSolveComplete(solveResults) Fires when RouteTask.solve() has completed.
Constructor Detail

esri.tasks.RouteTask(url)

Creates a new RouteTask object.
Parameters:
<String> url Required URL to the ArcGIS Server REST resource that represents a network analysis service. To obtain the URL, use Services Directory.
Code snippets:
routeTask = new esri.tasks.RouteTask("http://tasks.arcgisonline.com/ArcGIS/rest/services/NetworkAnalysis/ESRI_Route_NA/NAServer/Route");
Properties Detail

<String> url

URL to the ArcGIS Server REST resource that represents a network analysis service. To obtain the URL, use Services Directory.
Methods Detail

solve(params, callback?, errback?)

Solves the route against the route layer with the route parameters.
Return value: dojo.Deferred
Input Parameters:
<RouteParameters> params Required Route parameters used as input to generate the route.
<Function> callback Optional The function to call when the method has completed. The arguments in the function are the same as the onSolveComplete event.
<Function> errback Optional An error object is returned if an error occurs during task execution.
Code snippets:
routeParams = new esri.tasks.RouteParameters();
routeParams.stops = new esri.tasks.FeatureSet();
routeParams.returnRoutes = false;
routeParams.returnDirections = true;
routeParams.directionsLengthUnits = esri.Units.MILES;
routeParams.outSpatialReference = new esri.SpatialReference({ wkid:102100 });

dojo.connect(routeTask, "onSolveComplete", showRoute);

See also:
onSolveComplete  

Events Detail

onError(error)

Fires when an error occurs when executing the task.
Arguments:
<Error> error Error message returned in a JavaScript error object.

onSolveComplete(solveResults)

Fires when RouteTask.solve() has completed.
Arguments:
<Object> solveResults

At version 2.0 the signature changed to return an anonymous solveResult object. The solveResult object contains the following properties:

<RouteResult[]> routeResults Array of route results.
<Graphic[]> barriers Array of graphics representing the barriers. Barriers are returned only if RouteParameters.returnBarriers is true. For the list of attributes returned for each barrier, see the "Barrier properties" section in Finding the best route.
<Graphic[]> polygonBarriers Array of graphics representing the polygon barriers. Barriers are returned only if RouteParameters.returnPolygonBarriers is true.
<Graphic[]> polylineBarriers Array of graphics representing the polyline barriers. Barriers are returned only if RouteParameters.returnPolylineBarriers is true.
<NAMessage[]> message Message received when solve is completed. If a route cannot be solved, the message returned by the server identifies the route that could not be solved.
Code snippets:
function showRoute(solveResult) {
  var routeResults = solveResult.routeResults;
  var barriers = solveResult.barriers;
  var polygonBarriers = solveResult.polygonBarriers;
  var polylineBarriers = solveResult.polylineBarriers;
  var messages = solveResult.messages;
  ?
}