index.cjs 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. "use strict";Object.defineProperty(exports, "__esModule", {value: true});// index.ts
  2. var _helpers = require('@turf/helpers');
  3. var _invariant = require('@turf/invariant');
  4. function rhumbDestination(origin, distance, bearing, options = {}) {
  5. const wasNegativeDistance = distance < 0;
  6. let distanceInMeters = _helpers.convertLength.call(void 0,
  7. Math.abs(distance),
  8. options.units,
  9. "meters"
  10. );
  11. if (wasNegativeDistance) distanceInMeters = -Math.abs(distanceInMeters);
  12. const coords = _invariant.getCoord.call(void 0, origin);
  13. const destination = calculateRhumbDestination(
  14. coords,
  15. distanceInMeters,
  16. bearing
  17. );
  18. destination[0] += destination[0] - coords[0] > 180 ? -360 : coords[0] - destination[0] > 180 ? 360 : 0;
  19. return _helpers.point.call(void 0, destination, options.properties);
  20. }
  21. function calculateRhumbDestination(origin, distance, bearing, radius) {
  22. radius = radius === void 0 ? _helpers.earthRadius : Number(radius);
  23. const delta = distance / radius;
  24. const lambda1 = origin[0] * Math.PI / 180;
  25. const phi1 = _helpers.degreesToRadians.call(void 0, origin[1]);
  26. const theta = _helpers.degreesToRadians.call(void 0, bearing);
  27. const DeltaPhi = delta * Math.cos(theta);
  28. let phi2 = phi1 + DeltaPhi;
  29. if (Math.abs(phi2) > Math.PI / 2) {
  30. phi2 = phi2 > 0 ? Math.PI - phi2 : -Math.PI - phi2;
  31. }
  32. const DeltaPsi = Math.log(
  33. Math.tan(phi2 / 2 + Math.PI / 4) / Math.tan(phi1 / 2 + Math.PI / 4)
  34. );
  35. const q = Math.abs(DeltaPsi) > 1e-11 ? DeltaPhi / DeltaPsi : Math.cos(phi1);
  36. const DeltaLambda = delta * Math.sin(theta) / q;
  37. const lambda2 = lambda1 + DeltaLambda;
  38. return [
  39. (lambda2 * 180 / Math.PI + 540) % 360 - 180,
  40. phi2 * 180 / Math.PI
  41. ];
  42. }
  43. var turf_rhumb_destination_default = rhumbDestination;
  44. exports.default = turf_rhumb_destination_default; exports.rhumbDestination = rhumbDestination;
  45. //# sourceMappingURL=index.cjs.map