index.d.ts 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. import { Feature, Point, LineString, MultiLineString, Coord, Units } from "@turf/helpers";
  2. export interface NearestPointOnLine extends Feature<Point> {
  3. properties: {
  4. index?: number;
  5. dist?: number;
  6. location?: number;
  7. [key: string]: any;
  8. };
  9. }
  10. /**
  11. * Takes a {@link Point} and a {@link LineString} and calculates the closest Point on the (Multi)LineString.
  12. *
  13. * @name nearestPointOnLine
  14. * @param {Geometry|Feature<LineString|MultiLineString>} lines lines to snap to
  15. * @param {Geometry|Feature<Point>|number[]} pt point to snap from
  16. * @param {Object} [options={}] Optional parameters
  17. * @param {string} [options.units='kilometers'] can be degrees, radians, miles, or kilometers
  18. * @returns {Feature<Point>} closest point on the `line` to `point`. The properties object will contain three values: `index`: closest point was found on nth line part, `dist`: distance between pt and the closest point, `location`: distance along the line between start and the closest point.
  19. * @example
  20. * var line = turf.lineString([
  21. * [-77.031669, 38.878605],
  22. * [-77.029609, 38.881946],
  23. * [-77.020339, 38.884084],
  24. * [-77.025661, 38.885821],
  25. * [-77.021884, 38.889563],
  26. * [-77.019824, 38.892368]
  27. * ]);
  28. * var pt = turf.point([-77.037076, 38.884017]);
  29. *
  30. * var snapped = turf.nearestPointOnLine(line, pt, {units: 'miles'});
  31. *
  32. * //addToMap
  33. * var addToMap = [line, pt, snapped];
  34. * snapped.properties['marker-color'] = '#00f';
  35. */
  36. declare function nearestPointOnLine<G extends LineString | MultiLineString>(lines: Feature<G> | G, pt: Coord, options?: {
  37. units?: Units;
  38. }): NearestPointOnLine;
  39. export default nearestPointOnLine;