index.cjs 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. "use strict";Object.defineProperty(exports, "__esModule", {value: true});// index.ts
  2. var _circle = require('@turf/circle');
  3. var _linearc = require('@turf/line-arc');
  4. var _meta = require('@turf/meta');
  5. var _helpers = require('@turf/helpers');
  6. var _invariant = require('@turf/invariant');
  7. function sector(center, radius, bearing1, bearing2, options = {}) {
  8. options = options || {};
  9. if (!_helpers.isObject.call(void 0, options)) throw new Error("options is invalid");
  10. const properties = options.properties;
  11. if (!center) throw new Error("center is required");
  12. if (bearing1 === void 0 || bearing1 === null)
  13. throw new Error("bearing1 is required");
  14. if (bearing2 === void 0 || bearing2 === null)
  15. throw new Error("bearing2 is required");
  16. if (!radius) throw new Error("radius is required");
  17. if (typeof options !== "object") throw new Error("options must be an object");
  18. if (convertAngleTo360(bearing1) === convertAngleTo360(bearing2)) {
  19. return _circle.circle.call(void 0, center, radius, options);
  20. }
  21. const coords = _invariant.getCoords.call(void 0, center);
  22. const arc = _linearc.lineArc.call(void 0, center, radius, bearing1, bearing2, options);
  23. const sliceCoords = [[coords]];
  24. _meta.coordEach.call(void 0, arc, function(currentCoords) {
  25. sliceCoords[0].push(currentCoords);
  26. });
  27. sliceCoords[0].push(coords);
  28. return _helpers.polygon.call(void 0, sliceCoords, properties);
  29. }
  30. function convertAngleTo360(alpha) {
  31. let beta = alpha % 360;
  32. if (beta < 0) {
  33. beta += 360;
  34. }
  35. return beta;
  36. }
  37. var turf_sector_default = sector;
  38. exports.default = turf_sector_default; exports.sector = sector;
  39. //# sourceMappingURL=index.cjs.map