diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index cb876e3e..588749a3 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -23,6 +23,6 @@ jobs: - name: Run linting run: yarn lint - + - name: Run testing run: yarn test diff --git a/src/helper/getIntersectedLinesAndPoint.js b/src/helper/getIntersectedLinesAndPoint.js index 9c1b9476..e73ba345 100644 --- a/src/helper/getIntersectedLinesAndPoint.js +++ b/src/helper/getIntersectedLinesAndPoint.js @@ -15,15 +15,25 @@ const getIntersectedLinesAndPoint = (coordinate, lines, map, snapTolerance) => { const isPointAlreadyExist = {}; const mousePx = map.getPixelFromCoordinate(coordinate); - lines.forEach((lineA) => { - lines.forEach((lineB) => { - const intersections = OverlayOp.intersection( - parser.read(lineA.getGeometry()), - parser.read(lineB.getGeometry()), - ); - const coord = intersections?.getCoordinates()[0]; + const parsedLines = lines.map((line) => [ + line, + parser.read(line.getGeometry()), + ]); + parsedLines.forEach(([lineA, parsedLineA]) => { + parsedLines.forEach(([lineB, parsedLineB]) => { + if (lineA === lineB || isSameLines(lineA, lineB, map)) { + return; + } - if (coord && lineA !== lineB && !isSameLines(lineA, lineB, map)) { + let intersections; + try { + intersections = OverlayOp.intersection(parsedLineA, parsedLineB); + } catch (e) { + return; // The OverlayOp will sometimes error with topology errors for certain lines + } + + const coord = intersections?.getCoordinates()[0]; + if (coord) { intersections.getCoordinates().forEach(({ x, y }) => { if ( getDistance(map.getPixelFromCoordinate([x, y]), mousePx) <=