index.d.ts 1.2 KB

12345678910111213141516171819202122232425262728293031323334
  1. import { Coord, Feature, FeatureCollection, Point } from "@turf/helpers";
  2. export interface NearestPoint extends Feature<Point> {
  3. properties: {
  4. featureIndex: number;
  5. distanceToPoint: number;
  6. [key: string]: any;
  7. };
  8. }
  9. /**
  10. * Takes a reference {@link Point|point} and a FeatureCollection of Features
  11. * with Point geometries and returns the
  12. * point from the FeatureCollection closest to the reference. This calculation
  13. * is geodesic.
  14. *
  15. * @name nearestPoint
  16. * @param {Coord} targetPoint the reference point
  17. * @param {FeatureCollection<Point>} points against input point set
  18. * @returns {Feature<Point>} the closest point in the set to the reference point
  19. * @example
  20. * var targetPoint = turf.point([28.965797, 41.010086], {"marker-color": "#0F0"});
  21. * var points = turf.featureCollection([
  22. * turf.point([28.973865, 41.011122]),
  23. * turf.point([28.948459, 41.024204]),
  24. * turf.point([28.938674, 41.013324])
  25. * ]);
  26. *
  27. * var nearest = turf.nearestPoint(targetPoint, points);
  28. *
  29. * //addToMap
  30. * var addToMap = [targetPoint, points, nearest];
  31. * nearest.properties['marker-color'] = '#F00';
  32. */
  33. declare function nearestPoint(targetPoint: Coord, points: FeatureCollection<Point>): NearestPoint;
  34. export default nearestPoint;