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


JavaScript ArcGIS Portal.helperServices用法及代碼示例


基本信息

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

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.helperServices函數(或屬性)的定義如下:

helperServices Object


自從:ArcGIS 適用於 JavaScript 4.4 的 API

門戶提供的幫助服務。這對於確定相關方法的 URL 很有用。建議將這些 URL 與它們各自的 rest 模塊一起使用,而不是不推薦使用的輔助方法。

有關幫助服務的其他信息,請參閱 ArcGIS 服務器文檔中的 about utility services 主題。

例子:

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

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

  const map = new Map({
    basemap: "streets-navigation-vector",
    layers: [routingLayer]
  });

  const view = new MapView({
    container: "viewDiv",
    map: map,
    center: [-117.39966, 34.06873],
    zoom: 10
  });

  // 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: [175, 155, 215, 0.5],
    width: 5
  };

  // load Portal instance
  portal.load().then(function() {
    // display URLs to all helper services
    console.log("Show helperServices URLs: ", portal.helperServices);
    // 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 them on the map
  function showRouteInfo(routeSolveResult) {
    console.log("Show all results: ", routeSolveResult);
    const routeResult = routeSolveResult.routeResults[0].route;
    routeResult.symbol = routeSymbol;
    routingLayer.add(routeResult);
  }
});

相關用法


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