Skip to content

KBE3D / KBCore / turf / shortestPath

函数: shortestPath()

shortestPath(start: Coord, end: Coord, options?: { obstacles?: Polygon | Feature<Polygon, GeoJsonProperties> | FeatureCollection<Polygon, GeoJsonProperties>; units?: Units; resolution?: number; }): Feature<LineString>

Function

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

参数

start

Coord

point

end

Coord

point

options?

optional parameters

obstacles?

Polygon | Feature<Polygon, GeoJsonProperties> | FeatureCollection<Polygon, GeoJsonProperties>

areas which path cannot travel

units?

Units

unit in which resolution & minimum distance will be expressed in; Supports all valid Turf Units

.

resolution?

number

distance between matrix points on which the path will be calculated

返回

Feature<LineString>

shortest path between start and end

示例

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

//addToMap
var addToMap = [start, end, options.obstacles, path];

KBE3D @3.0.0 Copyright © 2024-present KBE3D