index.cjs 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. "use strict";Object.defineProperty(exports, "__esModule", {value: true});// index.ts
  2. var _centroid = require('@turf/centroid');
  3. var _rhumbbearing = require('@turf/rhumb-bearing');
  4. var _rhumbdistance = require('@turf/rhumb-distance');
  5. var _rhumbdestination = require('@turf/rhumb-destination');
  6. var _clone = require('@turf/clone');
  7. var _meta = require('@turf/meta');
  8. var _invariant = require('@turf/invariant');
  9. var _helpers = require('@turf/helpers');
  10. function transformRotate(geojson, angle, options) {
  11. options = options || {};
  12. if (!_helpers.isObject.call(void 0, options)) throw new Error("options is invalid");
  13. const pivot = options.pivot;
  14. const mutate = options.mutate;
  15. if (!geojson) throw new Error("geojson is required");
  16. if (angle === void 0 || angle === null || isNaN(angle))
  17. throw new Error("angle is required");
  18. if (angle === 0) return geojson;
  19. const pivotCoord = pivot != null ? pivot : _centroid.centroid.call(void 0, geojson);
  20. if (mutate === false || mutate === void 0) geojson = _clone.clone.call(void 0, geojson);
  21. _meta.coordEach.call(void 0, geojson, function(pointCoords) {
  22. const initialAngle = _rhumbbearing.rhumbBearing.call(void 0, pivotCoord, pointCoords);
  23. const finalAngle = initialAngle + angle;
  24. const distance = _rhumbdistance.rhumbDistance.call(void 0, pivotCoord, pointCoords);
  25. const newCoords = _invariant.getCoords.call(void 0,
  26. _rhumbdestination.rhumbDestination.call(void 0, pivotCoord, distance, finalAngle)
  27. );
  28. pointCoords[0] = newCoords[0];
  29. pointCoords[1] = newCoords[1];
  30. });
  31. return geojson;
  32. }
  33. var turf_transform_rotate_default = transformRotate;
  34. exports.default = turf_transform_rotate_default; exports.transformRotate = transformRotate;
  35. //# sourceMappingURL=index.cjs.map