Method Overview
Name | Return Type | Summary | Object |
---|---|---|---|
Promise<RouteSolveResult> | Solves the route against the route layer with the route parameters. more details | route |
Method Details
-
solve(url, params, requestOptions){Promise<RouteSolveResult>}
-
Solves the route against the route layer with the route parameters.
Parametersurl StringURL to the ArcGIS Server REST resource that represents a network analysis service.
params RouteParametersRoute parameters used as input to generate the route.
requestOptions ObjectoptionalAdditional options to be used for the data request (will override requestOptions defined during construction).
ReturnsType Description Promise<RouteSolveResult> When resolved, returns an instance of RouteSolveResult. Examplerequire([ "esri/rest/route", "esri/core/Collection", "esri/rest/support/RouteParameters", "esri/rest/support/Stop" ], function(route, Collection, RouteParameters, Stop) { // point the URL to a valid routing service const routeUrl = "https://route-api.arcgis.com/arcgis/rest/services/World/Route/NAServer/Route_World"; // create a Collection of new Stops const stops = new Collection([ new Stop({ geometry: { x: -117.59275, y: 34.06200 }, name: "Ontario Airport" }), new Stop({ geometry: { x: -117.19570, y: 34.05609 }, name: "Esri Campus" }) ]); // setup the RouteParameters with API key and Stops const routeParams = new RouteParameters({ // An authorization string used to access the routing service apiKey: "YOUR_API_KEY", stops }); // solve the route with the RouteParameters function solveRoute() { route.solve(routeUrl, routeParams).then(showRouteInfo); } // do something useful with the results // like display them to the console function showRouteInfo(routeSolveResult) { console.log("Show all results: ", routeSolveResult); console.log("Show the route information: ", routeSolveResult.routeResults[0].route); } solveRoute(); });