index.d.ts 1.5 KB

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