From 544366425ec79069f67a75f824b8619c34a5a28b Mon Sep 17 00:00:00 2001 From: Dmitrii Morozov Date: Sun, 4 May 2025 23:28:29 +0200 Subject: Smart reroute fix --- index.html | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/index.html b/index.html index 00a15a7..d885829 100755 --- a/index.html +++ b/index.html @@ -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"; -- cgit v1.2.3