# shortestPath

Returns the shortest path from start to end without colliding with any Feature in obstacles


参数 类型 描述
start Coord point
end Coord point
options Object 可选参数:见下文


属性 类型 默认值 描述
obstacles Geometry|Feature|FeatureCollection <Polygon>) areas which path cannot travel
minDistance (number) minimum distance between shortest path and obstacles
units string kilometers unit in which resolution & minimum distance will be expressed in; it can be degrees, radians, miles, kilometers, ...
resolution number 100 distance between matrix points on which the path will be calculateds


Feature <LineString> - shortest path between start and end


var start = [-5, -6];
var end = [9, -6];
var options = {
  obstacles: turf.polygon([[[0, -7], [5, -7], [5, -3], [0, -3], [0, -7]]]) // 注意:polygon首尾坐标要一致

var path = turf.shortestPath(start, end, options);
Last Updated: 6/21/2023, 11:40:17 PM