Skip to content

描述 ​

返回从 start 到 end 的最短 path,不碰撞障碍物 FeatureCollection<Polygon> 中的任何 Feature。

参数 ​

名称类型描述
startCoord点
endCoord点
options?Object可选参数 (默认 {})
options.obstacles?Polygon | Feature<Polygon> | FeatureCollection<Polygon>路径不能穿过的区域
options.units?Units分辨率和最小距离将以何种单位表示;支持所有有效的 Turf Units。 (默认 'kilometers')
options.resolution?number路径将计算在其上的矩阵点之间的距离 (默认 100)

返回值 ​

Feature<LineString> 起点和终点之间的最短路径

示例 ​

javascript
var start = [-5, -6];
var end = [9, -6];
var options = {
  obstacles: turf.polygon([
    [
      [0, -7],
      [5, -7],
      [5, -3],
      [0, -3],
      [0, -7],
    ],
  ]).geometry,
};

var path = turf.shortestPath(start, end, options);

安装 ​

javascript
$ npm install @turf/shortest-path

import { shortestPath } from "@turf/shortest-path";
const result = shortestPath(...);
javascript
$ npm install @turf/turf

import * as turf from "@turf/turf";
const result = turf.shortestPath(...);