index.js 736 B

1234567891011121314151617181920212223
  1. // index.ts
  2. import * as polyclip from "polyclip-ts";
  3. import { multiPolygon, polygon } from "@turf/helpers";
  4. import { geomEach } from "@turf/meta";
  5. function union2(features, options = {}) {
  6. const geoms = [];
  7. geomEach(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 polygon(unioned[0], options.properties);
  16. else return multiPolygon(unioned, options.properties);
  17. }
  18. var turf_union_default = union2;
  19. export {
  20. turf_union_default as default,
  21. union2 as union
  22. };
  23. //# sourceMappingURL=index.js.map