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


JavaScript ArcGIS RouteParameters.travelMode用法及代碼示例

基本信息

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

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

ESM: import RouteParameters from "@arcgis/core/rest/support/RouteParameters";

類: esri/rest/support/RouteParameters

繼承: RouteParameters > Accessor

自從:用於 JavaScript 4.20 的 ArcGIS API

用法說明

RouteParameters.travelMode函數(或屬性)的定義如下:

travelMode TravelMode


出行方式代表一種交通工具,例如駕車或步行。出行模式定義了車輛或行人的物理特征。

travelMode 參數的值是 JSON 對象,其中包含您的服務支持的出行模式的設置。要獲得支持的出行模式,請執行retrieveTravelModes 操作。您可以使用以下表單請求檢索出行模式:https://route.arcgis.com/arcgis/rest/services/World/Route/NAServer/Route_World/retrieveTravelModes?f=json

例子:

// Display the fastest walking time route between two existing graphics.
const apiKey = "<your-api-key>";
const url = "https://route-api.arcgis.com/arcgis/rest/services/World/Route/NAServer/Route_World";

// Obtain the routing service's description. The description contains all preset travel modes.
const serviceDescription = await networkService.fetchServiceDescription(url, apiKey);

// Find the named travel mode called "Walking Time".
const { supportedTravelModes } = serviceDescription;
const travelMode = supportedTravelModes.find((mode) => mode.name === "Walking Time");

// Construct the route parameter object.
const routeParameters = new RouteParameters({
  apiKey,
  stops: new FeatureSet({
    features: view.graphics.toArray()
  }),
  returnDirections: true,
  travelMode
});

// Solve the route and add the path representing the fastest walk path to the map.
const routeContainer = await route.solve(url, routeParameters);
for (const routeResult of routeContainer.routeResults) {
  const { routeLayer } = routeResult;
  routeLayer.symbol = {
    type: "simple-line",
    color: [5, 150, 255],
    width: 3
  };
  view.graphics.add(routeLayer);
}

相關用法


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