diff options
author | Dmitrii Morozov <snoopdesigns@gmail.com> | 2025-05-04 23:28:29 +0200 |
---|---|---|
committer | Dmitrii Morozov <snoopdesigns@gmail.com> | 2025-05-04 23:28:29 +0200 |
commit | 544366425ec79069f67a75f824b8619c34a5a28b (patch) | |
tree | c5bd4d3ecc25bd0e2b5fd8ef03a243a13d292d98 | |
parent | 4870596d0f3c8f812e0684faa906d6afe79ae01e (diff) |
Smart reroute fix
-rwxr-xr-x | index.html | 16 |
1 files changed, 15 insertions, 1 deletions
@@ -111,7 +111,21 @@ } } - const remainingCoords = coords.slice(closestIndex); + // After finding closestIndex + const lookahead = 10; + let forwardIndex = closestIndex; + + for (let i = closestIndex + 1; i < Math.min(closestIndex + lookahead, coords.length); i++) { + const [lat, lon] = coords[i].split(',').map(Number); + const dist = getDistance(userLat, userLon, lat, lon); + // Prefer slightly farther point if it's still reasonably close and farther along + if (dist < minDist * 1.5) { + forwardIndex = i; + minDist = dist; + } + } + + const remainingCoords = coords.slice(forwardIndex); const selectedCoords = downsampleWaypoints(remainingCoords); const startCoord = "Current+Location"; |