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


JavaScript ArcGIS DirectionLine用法及代码示例


基本信息

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

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

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

类: esri/rest/support/DirectionLine

继承: DirectionLine > Accessor

自从:用于 JavaScript 4.23 的 ArcGIS API

用法说明

DirectionLine 表示与各个方向项关联的折线。

例子:

// Print the distance and time between each direction.
const routeLayer = new RouteLayer({
  portalItem: {
    id: "69569b47b1e445b8a42ec12feab41ce9"
  }
});
await routeLayer.load();

const locale = "en-US";
const formatMinutes = new Intl.NumberFormat(locale, {
  minimumFractionDigits: 1,
  maximumFractionDigits: 1
});
const formatDistance = new Intl.NumberFormat(locale, {
  minimumFractionDigits: 0,
  maximumFractionDigits: 0
});

 for (const directionLine of routeLayer.directionLines) {
  const { distance, duration } = directionLine;
  console.log(`Drive ${formatDistance.format(distance)} meters for ${formatMinutes.format(duration)} minutes.`);
}

// Drive 76 meters for 0.4 minutes.
// Drive 77 meters for 0.2 minutes.
// Drive 150 meters for 0.2 minutes.
// Drive 3,670 meters for 2.6 minutes.
// Drive 307 meters for 0.2 minutes.
// Drive 6,293 meters for 4.5 minutes.
// Drive 42,276 meters for 29.2 minutes.
// etc.

相关用法


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