fix(annotations): label a 996 m line or route as 1.0 km, not 1000 m

Placed route, arrow and drawn-line labels picked metres before rounding
to ten metres, so anything from 995 m to 1 km read "1000 m", even where
the draw hint for the same line read "1.0 km". The label now rounds
first, then picks the unit, and does the same at the 10 km cut, where
9,960 m read "10.0 km".
This commit is contained in:
Aditya committed 2026-10-28 15:34:28 +05:30
1 parent a4d3701c3c
commit e4a964375a
3 files changed
+21 -3

No files matched your search

+5 -2
View File
@@ -1573,8 +1573,11 @@ function greatCircleM(a, b) {
function formatDistance(m) {
if (!Number.isFinite(m)) return null;
if (m >= 1000) return `${(m / 1000).toFixed(m >= 10000 ? 0 : 1)} km`;
return `${Math.round(m / 10) * 10} m`;
// Round before each unit cut: 996 m was printed as "1000 m" and
// 9,960 m as "10.0 km".
const tens = Math.round(m / 10) * 10;
if (tens < 1000) return `${tens} m`;
return `${(m / 1000).toFixed(Math.round(m / 100) >= 100 ? 0 : 1)} km`;
}
function composeRouteLabel(baseLabel, distM, durS, mode, fallback) {