index.cjs 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. "use strict";Object.defineProperty(exports, "__esModule", {value: true});// index.ts
  2. var _bearing = require('@turf/bearing');
  3. var _destination = require('@turf/destination');
  4. var _distance = require('@turf/distance');
  5. var _helpers = require('@turf/helpers');
  6. var _invariant = require('@turf/invariant');
  7. function along(line, distance, options = {}) {
  8. const geom = _invariant.getGeom.call(void 0, line);
  9. const coords = geom.coordinates;
  10. let travelled = 0;
  11. for (let i = 0; i < coords.length; i++) {
  12. if (distance >= travelled && i === coords.length - 1) {
  13. break;
  14. } else if (travelled >= distance) {
  15. const overshot = distance - travelled;
  16. if (!overshot) {
  17. return _helpers.point.call(void 0, coords[i]);
  18. } else {
  19. const direction = _bearing.bearing.call(void 0, coords[i], coords[i - 1]) - 180;
  20. const interpolated = _destination.destination.call(void 0,
  21. coords[i],
  22. overshot,
  23. direction,
  24. options
  25. );
  26. return interpolated;
  27. }
  28. } else {
  29. travelled += _distance.distance.call(void 0, coords[i], coords[i + 1], options);
  30. }
  31. }
  32. return _helpers.point.call(void 0, coords[coords.length - 1]);
  33. }
  34. var turf_along_default = along;
  35. exports.along = along; exports.default = turf_along_default;
  36. //# sourceMappingURL=index.cjs.map