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


JavaScript ArcGIS RouteInfo用法及代碼示例


基本信息

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

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

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

類: esri/rest/support/RouteInfo

繼承: RouteInfo > Accessor

自從:用於 JavaScript 4.23 的 ArcGIS API

用法說明

RouteInfo 包含有關已解決路線的信息,包括路線幾何形狀以及總距離和時間。

例子:

// Display the route name and overall distance and duration.
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
});
const formatDate = new Intl.DateTimeFormat(locale, {
  year: 'numeric',
  month: 'numeric',
  day: 'numeric',
  hour: 'numeric',
  minute: 'numeric',
  second: 'numeric',
  timeZone: "America/Los_Angeles"
});

const { name, startTime, endTime, totalDistance, totalDuration } = routeLayer.routeInfo;
console.log(`Route name:      ${name}`);
console.log(`Start Time:      ${formatDate.format(startTime)}`);
console.log(`End Time:        ${formatDate.format(endTime)}`);
console.log(`Travel Time:     ${formatMinutes.format(totalDuration)} minutes`);
console.log(`Travel Distance: ${formatDistance.format(totalDistance)} meters`);

// Route name:      Kenoak Pl, Pomona, California, 91768 — 16561 Valley Blvd, Fontana, California, 92335
// Start Time:      12/7/2020, 3:58:50 PM
// End Time:        12/7/2020, 6:12:20 PM
// Travel Time:     133.5 minutes
// Travel Distance: 173,148 meters

相關用法


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