index.cjs 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. "use strict";Object.defineProperty(exports, "__esModule", {value: true});// index.ts
  2. var _meta = require('@turf/meta');
  3. var _helpers = require('@turf/helpers');
  4. var _invariant = require('@turf/invariant');
  5. var _clone = require('@turf/clone');
  6. var _rhumbdestination = require('@turf/rhumb-destination');
  7. function transformTranslate(geojson, distance, direction, options) {
  8. options = options || {};
  9. if (!_helpers.isObject.call(void 0, options)) throw new Error("options is invalid");
  10. var units = options.units;
  11. var zTranslation = options.zTranslation;
  12. var mutate = options.mutate;
  13. if (!geojson) throw new Error("geojson is required");
  14. if (distance === void 0 || distance === null || isNaN(distance))
  15. throw new Error("distance is required");
  16. if (zTranslation && typeof zTranslation !== "number" && isNaN(zTranslation))
  17. throw new Error("zTranslation is not a number");
  18. zTranslation = zTranslation !== void 0 ? zTranslation : 0;
  19. if (distance === 0 && zTranslation === 0) return geojson;
  20. if (direction === void 0 || direction === null || isNaN(direction))
  21. throw new Error("direction is required");
  22. if (distance < 0) {
  23. distance = -distance;
  24. direction = direction + 180;
  25. }
  26. if (mutate === false || mutate === void 0) geojson = _clone.clone.call(void 0, geojson);
  27. _meta.coordEach.call(void 0, geojson, function(pointCoords) {
  28. var newCoords = _invariant.getCoords.call(void 0,
  29. _rhumbdestination.rhumbDestination.call(void 0, pointCoords, distance, direction, { units })
  30. );
  31. pointCoords[0] = newCoords[0];
  32. pointCoords[1] = newCoords[1];
  33. if (zTranslation && pointCoords.length === 3)
  34. pointCoords[2] += zTranslation;
  35. });
  36. return geojson;
  37. }
  38. var turf_transform_translate_default = transformTranslate;
  39. exports.default = turf_transform_translate_default; exports.transformTranslate = transformTranslate;
  40. //# sourceMappingURL=index.cjs.map