index.js 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. // index.ts
  2. import { feature, featureCollection, point } from "@turf/helpers";
  3. // lib/sweepline-intersections-export.ts
  4. import lib from "sweepline-intersections";
  5. var sweeplineIntersections = lib;
  6. // index.ts
  7. function lineIntersect(line1, line2, options = {}) {
  8. const { removeDuplicates = true, ignoreSelfIntersections = true } = options;
  9. let features = [];
  10. if (line1.type === "FeatureCollection")
  11. features = features.concat(line1.features);
  12. else if (line1.type === "Feature") features.push(line1);
  13. else if (line1.type === "LineString" || line1.type === "Polygon" || line1.type === "MultiLineString" || line1.type === "MultiPolygon") {
  14. features.push(feature(line1));
  15. }
  16. if (line2.type === "FeatureCollection")
  17. features = features.concat(line2.features);
  18. else if (line2.type === "Feature") features.push(line2);
  19. else if (line2.type === "LineString" || line2.type === "Polygon" || line2.type === "MultiLineString" || line2.type === "MultiPolygon") {
  20. features.push(feature(line2));
  21. }
  22. const intersections = sweeplineIntersections(
  23. featureCollection(features),
  24. ignoreSelfIntersections
  25. );
  26. let results = [];
  27. if (removeDuplicates) {
  28. const unique = {};
  29. intersections.forEach((intersection) => {
  30. const key = intersection.join(",");
  31. if (!unique[key]) {
  32. unique[key] = true;
  33. results.push(intersection);
  34. }
  35. });
  36. } else {
  37. results = intersections;
  38. }
  39. return featureCollection(results.map((r) => point(r)));
  40. }
  41. var turf_line_intersect_default = lineIntersect;
  42. export {
  43. turf_line_intersect_default as default,
  44. lineIntersect
  45. };
  46. //# sourceMappingURL=index.js.map