Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: hide topology errors in line hit detection & optimizations #261

Merged
merged 2 commits into from
Jun 25, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 18 additions & 7 deletions src/helper/getIntersectedLinesAndPoint.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +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 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;
}

let intersections;
try {
intersections = OverlayOp.intersection(parsedLineA, parsedLineB);
} catch (e) {
return; // The OverlayOp will sometimes error with topology errors for certain lines
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@megawac Have you some more precise info about those topology error ? Could be nice to have an example.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I seem to recall them occurring quite often when #267 was occurring... I'll see if I can track down if there was more context on internal tickets.

Copy link
Contributor Author

@megawac megawac May 28, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is from the original ticket reported on our side. So in the case the case of the error, parsedLineB snap line appears to be invalid from the error below. There is a video of the error occurring but I'd have to get clearance to share I believe

Uncaught TopologyException: found non-noded intersection between LINESTRING ( 9.952973188580247 2.35845900632583, 11.739231890263671 2.3680559374052663 ) and LINESTRING ( 9.952973188580248 2.35845900632583, 11.452360499376073 508.73944164968873 ) [ (9.952973188580248, 2.35845900632583, NaN) ]
    at g.checkValid (bundle.js)
    at E.checkValid (bundle.js)
    at E.checkValid (bundle.js)
    at A.computeOverlay (bundle.js)
    at A.getResultGeometry (bundle.js)
    at A.overlayOp (bundle.js)
    at E.getResultGeometry (bundle.js)
    at E.overlayOp (bundle.js)
    at A.intersection (bundle.js)
    at bundle.js
    at Array.forEach (<anonymous>)
    at bundle.js
    at Array.forEach (<anonymous>)
    at J (bundle.js)
    at ee.drawSnapLines (bundle.js)
    at ee.onMove (bundle.js)
    at a.handleEvent (bundle.js)
    at le.handleMapBrowserEvent (bundle.js)
    at u.dispatchEvent (bundle.js)
    at u.relayMoveEvent_ (bundle.js)
    at HTMLDivElement.d (bundle.js)

}

const coord = intersections?.getCoordinates()[0];
if (coord && lineA !== lineB && !isSameLines(lineA, lineB, map)) {
if (coord) {
intersections.getCoordinates().forEach(({ x, y }) => {
if (
getDistance(map.getPixelFromCoordinate([x, y]), mousePx) <=
Expand Down