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


JavaScript ArcGIS TravelMode用法及代码示例


基本信息

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

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

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

类: esri/rest/support/TravelMode

继承: TravelMode > Accessor

自从:用于 JavaScript 4.20 的 ArcGIS API

用法说明

TravelMode 是一组特征,用于定义车辆、自行车或行人等对象如何沿街道网络移动。在寻找方向以确定车辆或行人如何行驶以及他们可以去哪里时,会考虑这些特征。要获取支持的出行模式列表、查找默认出行模式以及查找和使用特定出行模式,您可以使用 networkService.fetchServiceDescription() 方法:

// 1. Get the default and supported travel modes of a route service
const apiKey = "<your api key>";
const url = "https://route-api.arcgis.com/arcgis/rest/services/World/Route/NAServer/Route_World";
const serviceDescription = await fetchServiceDescription(url, apiKey);
const { defaultTravelMode, supportedTravelModes } = serviceDescription;
console.log(`The id of the default travel mode is: ${defaultTravelMode}.`);
console.log(`This service has ${supportedTravelModes.length} preset travel modes`);
// 2. Find and use the "Driving Time" travel mode
const apiKey = "<your api key>";
const url = "https://route-api.arcgis.com/arcgis/rest/services/World/Route/NAServer/Route_World";
const serviceDescription = await fetchServiceDescription(url, apiKey);
const { supportedTravelModes } = serviceDescription;
const driveTimeTravelMode = supportedTravelModes.find((mode) => mode.name === "Driving Time");

// Solve a route using the "Driving Time" travel mode
const routeParameters = {
  stops: stopsFeatureSet, // route stops
  travelMode: driveTimeTravelMode
};
const result = await solve(url, routeParameters);

对于ArcGIS Enterprise 服务,出行模式的默认值基于使用网络分析函数发布Map服务时的图层设置。打开服务说明页面以查看参数的默认值。

相关用法


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