Skip to main content
Version: 7.3.0

shortestPath

描述​

🌐 Description

返回从起点到终点的最短路径,且在障碍物FeatureCollection<多边形>中不与任何特性碰撞

🌐 Returns the shortest path from start to end without colliding with any Feature in obstacles FeatureCollection<Polygon>

参数​

🌐 Parameters

名称类型描述
开始坐标点
结束坐标点
options?对象可选参数 (默认 {})
options.obstacles?多边形 | 要素<多边形> | 要素集合<多边形>路径无法通过的区域
options.units?单位分辨率和最小距离的表示单位;支持所有有效的 Turf 单位。(默认 'kilometers')
options.resolution?数字将用于计算路径的矩阵点之间的距离 (默认 100)

返回​

🌐 Returns

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

示例​

🌐 Examples

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);

安装​

🌐 Installation

$ npm install @turf/shortest-path

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

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