index.js 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. // index.ts
  2. import { coordEach } from "@turf/meta";
  3. import { isObject } from "@turf/helpers";
  4. import { getCoords } from "@turf/invariant";
  5. import { clone } from "@turf/clone";
  6. import { rhumbDestination } from "@turf/rhumb-destination";
  7. function transformTranslate(geojson, distance, direction, options) {
  8. options = options || {};
  9. if (!isObject(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(geojson);
  27. coordEach(geojson, function(pointCoords) {
  28. var newCoords = getCoords(
  29. rhumbDestination(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. export {
  40. turf_transform_translate_default as default,
  41. transformTranslate
  42. };
  43. //# sourceMappingURL=index.js.map