index.js 783 B

123456789101112131415161718192021222324
  1. // index.ts
  2. import { multiPolygon, polygon } from "@turf/helpers";
  3. import { geomEach } from "@turf/meta";
  4. import * as polyclip from "polyclip-ts";
  5. function intersect(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 specify at least 2 geometries");
  12. }
  13. const intersection2 = polyclip.intersection(geoms[0], ...geoms.slice(1));
  14. if (intersection2.length === 0) return null;
  15. if (intersection2.length === 1)
  16. return polygon(intersection2[0], options.properties);
  17. return multiPolygon(intersection2, options.properties);
  18. }
  19. var turf_intersect_default = intersect;
  20. export {
  21. turf_intersect_default as default,
  22. intersect
  23. };
  24. //# sourceMappingURL=index.js.map