index.cjs 1.2 KB

1234567891011121314151617181920212223
  1. "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { newObj[key] = obj[key]; } } } newObj.default = obj; return newObj; } }// index.ts
  2. var _polyclipts = require('polyclip-ts'); var polyclip = _interopRequireWildcard(_polyclipts);
  3. var _helpers = require('@turf/helpers');
  4. var _meta = require('@turf/meta');
  5. function union2(features, options = {}) {
  6. const geoms = [];
  7. _meta.geomEach.call(void 0, features, (geom) => {
  8. geoms.push(geom.coordinates);
  9. });
  10. if (geoms.length < 2) {
  11. throw new Error("Must have at least 2 geometries");
  12. }
  13. const unioned = polyclip.union(geoms[0], ...geoms.slice(1));
  14. if (unioned.length === 0) return null;
  15. if (unioned.length === 1) return _helpers.polygon.call(void 0, unioned[0], options.properties);
  16. else return _helpers.multiPolygon.call(void 0, unioned, options.properties);
  17. }
  18. var turf_union_default = union2;
  19. exports.default = turf_union_default; exports.union = union2;
  20. //# sourceMappingURL=index.cjs.map