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


JavaScript ArcGIS RouteLayer用法及代码示例


基本信息

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

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

ESM: import RouteLayer from "@arcgis/core/layers/RouteLayer";

类: esri/layers/RouteLayer

继承: RouteLayer > Layer > Accessor

自从:用于 JavaScript 4.23 的 ArcGIS API

用法说明

RouteLayer 是用于可视化和解决路线的图层。已解决的路线包括turn-by-turn 方向,可以作为门户项目或网络Map的一部分从ArcGIS Online 或 Enterprise 中存储和检索。

RouteLayer 由两个或多个停靠点以及可选的点、多边形和折线障碍组成。已解决路线的结果可从 DirectionLines、directionPoints 和 RouteInfo 属性访问。结果包括总行程时间、距离和turn-by-turn方向。

已知限制

目前,RouteLayer 在 3D SceneViews 中不受支持。

例子:

// Routing with the RouteLayer's default route service requires an apikey.
const apiKey = "<your api key>";

// A minimum of two stops is required for routing.
const stops = [
  new Stop({ geometry: { x: -117.1825, y: 34.054722 }}),
  new Stop({ geometry: { x: -116.545278, y: 33.830278 }})
];

// Create route layer and assign the stops. Only solved routelayers will be rendered.
const routeLayer = new RouteLayer({
  stops
});

// Create a view and add the routelayer to the view's map.
const view = new MapView({
  container: "viewDiv",
  map: new Map({
    basemap: "dark-gray-vector",
    layers: [ routeLayer ]
  })
});

// Wait for the view to load since we'll be zooming to the extent of the zoomed solution.
view.when().then(async () => {
  // Solve the route using routelayer stops and barries and additional properties from the parsed RouteParameters
  // object. Use the RouteParameters to provide the apiKey and other setting like directions language and travel
  // mode.
  const results = await routeLayer.solve({ apiKey });

  // Use the returned result to update the RouteLayer. This method will overwrite the stops, barriers, directions and
  // routeInfo properties.
  routeLayer.update(results);

  // Zoom to the extent of the solve route.
  view.goTo(routeLayer.routeInfo.geometry);
});

相关用法


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