Skip to content

Commit ae85670

Browse files
authored
fix: hide topology errors in line hit detection & optimizations
1 parent 3fe1e75 commit ae85670

File tree

2 files changed

+19
-9
lines changed

2 files changed

+19
-9
lines changed

.github/workflows/lint.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,6 @@ jobs:
2323

2424
- name: Run linting
2525
run: yarn lint
26-
26+
2727
- name: Run testing
2828
run: yarn test

src/helper/getIntersectedLinesAndPoint.js

+18-8
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,25 @@ const getIntersectedLinesAndPoint = (coordinate, lines, map, snapTolerance) => {
1515
const isPointAlreadyExist = {};
1616
const mousePx = map.getPixelFromCoordinate(coordinate);
1717

18-
lines.forEach((lineA) => {
19-
lines.forEach((lineB) => {
20-
const intersections = OverlayOp.intersection(
21-
parser.read(lineA.getGeometry()),
22-
parser.read(lineB.getGeometry()),
23-
);
24-
const coord = intersections?.getCoordinates()[0];
18+
const parsedLines = lines.map((line) => [
19+
line,
20+
parser.read(line.getGeometry()),
21+
]);
22+
parsedLines.forEach(([lineA, parsedLineA]) => {
23+
parsedLines.forEach(([lineB, parsedLineB]) => {
24+
if (lineA === lineB || isSameLines(lineA, lineB, map)) {
25+
return;
26+
}
2527

26-
if (coord && lineA !== lineB && !isSameLines(lineA, lineB, map)) {
28+
let intersections;
29+
try {
30+
intersections = OverlayOp.intersection(parsedLineA, parsedLineB);
31+
} catch (e) {
32+
return; // The OverlayOp will sometimes error with topology errors for certain lines
33+
}
34+
35+
const coord = intersections?.getCoordinates()[0];
36+
if (coord) {
2737
intersections.getCoordinates().forEach(({ x, y }) => {
2838
if (
2939
getDistance(map.getPixelFromCoordinate([x, y]), mousePx) <=

0 commit comments

Comments
 (0)