當前位置: 首頁>>代碼示例 >>用法及示例精選 >>正文


JavaScript ArcGIS route.solve用法及代碼示例


基本信息

以下是所在類或對象的基本信息。

AMD: require(["esri/rest/route"], (route) => { /* code goes here */ });

ESM: import * as route from "@arcgis/core/rest/route";

對象: esri/rest/route

自從:用於 JavaScript 4.19 的 ArcGIS API

用法說明

route.solve函數(或屬性)的定義如下:

solve (url, params, requestOptions) {Promise<RouteSolveResult>}


使用路由參數求解針對路由層的路由。

參數:

類型說明
url String

表示網絡分析服務的 ArcGIS 服務器 REST 資源的 URL。

用作生成路由的輸入的路由參數。

requestOptions Object
可選的

用於數據請求的附加options(將覆蓋構造期間定義的 requestOptions)。

返回:

類型 說明
Promise<RouteSolveResult> 解析後,返回 RouteSolveResult 的實例。

例子:

require([
  "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();
});

相關用法


注:本文由純淨天空篩選整理自arcgis.com大神的英文原創作品 route.solve。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。