Skip to content

KBE3D / KBCore / turf / nearestPoint

函数: nearestPoint()

nearestPoint<P>(targetPoint: Coord, points: FeatureCollection<Point, P>, options?: { units?: Units; }): NearestPoint<P>

Function

Takes a reference point and a FeatureCollection of Features with Point geometries and returns the point from the FeatureCollection closest to the reference. This calculation is geodesic.

类型参数

P

P extends GeoJsonProperties = GeoJsonProperties

参数

targetPoint

Coord

the reference point

points

FeatureCollection<Point, P>

against input point set

options?

Optional parameters

units?

Units

the units of the numeric result. Supports all valid Turf Units

.

返回

NearestPoint<P>

the closest point in the set to the reference point

示例

ts
var targetPoint = turf.point([28.965797, 41.010086], {"marker-color": "#0F0"});
var points = turf.featureCollection([
    turf.point([28.973865, 41.011122]),
    turf.point([28.948459, 41.024204]),
    turf.point([28.938674, 41.013324])
]);

var nearest = turf.nearestPoint(targetPoint, points);

//addToMap
var addToMap = [targetPoint, points, nearest];
nearest.properties['marker-color'] = '#F00';

KBE3D @3.0.0 Copyright © 2024-present KBE3D