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


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。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。