当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


JavaScript ArcGIS Portal.createRouteTask用法及代码示例


基本信息

以下是所在类或对象的基本信息。

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

ESM: import Portal from "@arcgis/core/portal/Portal";

类: esri/portal/Portal

继承: Portal > Accessor

自从:用于 JavaScript 4.0 的 ArcGIS API

用法说明

Portal.createRouteTask函数(或属性)的定义如下:

createRouteTask () {Promise<RouteTask>}


自从:ArcGIS 适用于 JavaScript 4.12 的 API
已弃用 从 4.21 版本开始。请使用 route 和 helperServices 代替。

一个帮助函数,它返回门户的 RouteTask helper service 的实例。

返回:

类型 说明
Promise<RouteTask> 解析后,返回 RouteTask 的实例。

例子:

// example using "esri/rest/route" with helperServices

require([
  "esri/portal/Portal",
  "esri/core/Collection",
  "esri/rest/route",
  "esri/rest/support/RouteParameters",
  "esri/rest/support/Stop",
  "esri/layers/GraphicsLayer",
  ...
], function(Portal, Collection, route, RouteParameters, Stop, GraphicsLayer, ... ) {

  // create new Portal object with relevant URL
  const portal = new Portal({
     url: "YOUR_PORTAL_URL"
  });

  // the stops and route result will be stored in this layer
  const routingLayer = new GraphicsLayer();

  // 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
  });

  // define the symbology used to display the route
  const routeSymbol = {
    type: "simple-line", // autocasts as SimpleLineSymbol()
    color: [0, 0, 255, 0.5],
    width: 5
  };

  // load Portal instance
  portal.load().then(function() {
    // access helperServices from the Portal instance
    // to get the routing URL of interest
    const routeURL = portal.helperServices.route.url;
    // use helperServices to perform routing
    route.solve(routeURL, routeParams).then(showRouteInfo);
  }

  // do something useful with the results
  // like display them to the console
  // or display it on the map
  function showRouteInfo(routeSolveResult) {
    console.log("Show all results: ", routeSolveResult);
    console.log("Show the route information: ", routeSolveResult.routeResults[0].route);
    const routeResult = routeSolveResult.routeResults[0].route;
    routeResult.symbol = routeSymbol;
    routingLayer.add(routeResult);
    map.add(routingLayer);
  }
});

相关用法


注:本文由纯净天空筛选整理自arcgis.com大神的英文原创作品 Portal.createRouteTask。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。