From: Tom Hughes Date: Sun, 9 Mar 2025 14:57:32 +0000 (+0000) Subject: Merge remote-tracking branch 'upstream/pull/5781' X-Git-Tag: live~12 X-Git-Url: https://git.openstreetmap.org./rails.git/commitdiff_plain/dd57602d7e97a8141cee0476a5a48e31917d07b6?hp=95b8297955268874bbc4dc657e96f5bc1f0fabb8 Merge remote-tracking branch 'upstream/pull/5781' --- diff --git a/app/assets/javascripts/index/directions.js b/app/assets/javascripts/index/directions.js index 2d948d4b2..aee262e02 100644 --- a/app/assets/javascripts/index/directions.js +++ b/app/assets/javascripts/index/directions.js @@ -70,11 +70,28 @@ OSM.Directions = function (map) { OSM.router.route("/" + OSM.formatHash(map)); }); - function formatDistance(m) { - const unitTemplate = "javascripts.directions.distance_"; - if (m < 1000) return I18n.t(unitTemplate + "m", { distance: Math.round(m) }); - if (m < 10000) return I18n.t(unitTemplate + "km", { distance: (m / 1000.0).toFixed(1) }); - return I18n.t(unitTemplate + "km", { distance: Math.round(m / 1000) }); + function formatTotalDistance(m) { + if (m < 1000) { + return I18n.t("javascripts.directions.distance_m", { distance: Math.round(m) }); + } else if (m < 10000) { + return I18n.t("javascripts.directions.distance_km", { distance: (m / 1000.0).toFixed(1) }); + } else { + return I18n.t("javascripts.directions.distance_km", { distance: Math.round(m / 1000) }); + } + } + + function formatStepDistance(m) { + if (m < 5) { + return ""; + } else if (m < 200) { + return I18n.t("javascripts.directions.distance_m", { distance: String(Math.round(m / 10) * 10) }); + } else if (m < 1500) { + return I18n.t("javascripts.directions.distance_m", { distance: String(Math.round(m / 100) * 100) }); + } else if (m < 5000) { + return I18n.t("javascripts.directions.distance_km", { distance: String(Math.round(m / 100) / 10) }); + } else { + return I18n.t("javascripts.directions.distance_km", { distance: String(Math.round(m / 1000)) }); + } } function formatHeight(m) { @@ -147,7 +164,7 @@ OSM.Directions = function (map) { } const distanceText = $("

").append( - I18n.t("javascripts.directions.distance") + ": " + formatDistance(route.distance) + ". " + + I18n.t("javascripts.directions.distance") + ": " + formatTotalDistance(route.distance) + ". " + I18n.t("javascripts.directions.time") + ": " + formatTime(route.time) + "."); if (typeof route.ascend !== "undefined" && typeof route.descend !== "undefined") { distanceText.append( @@ -177,7 +194,7 @@ OSM.Directions = function (map) { row.append(""); } row.append("" + instruction); - row.append("" + getDistText(dist)); + row.append("" + formatStepDistance(dist)); row.on("click", function () { popup @@ -218,14 +235,6 @@ OSM.Directions = function (map) { }).finally(function () { controller = null; }); - - function getDistText(dist) { - if (dist < 5) return ""; - if (dist < 200) return String(Math.round(dist / 10) * 10) + "m"; - if (dist < 1500) return String(Math.round(dist / 100) * 100) + "m"; - if (dist < 5000) return String(Math.round(dist / 100) / 10) + "km"; - return String(Math.round(dist / 1000)) + "km"; - } } function hideRoute(e) { diff --git a/config/eslint.config.mjs b/config/eslint.config.mjs index a24dc08f5..6d695bbf6 100644 --- a/config/eslint.config.mjs +++ b/config/eslint.config.mjs @@ -102,7 +102,6 @@ export default [ "no-caller": "error", "no-console": "warn", "no-div-regex": "error", - "no-else-return": ["error", { allowElseIf: false }], "no-eq-null": "error", "no-eval": "error", "no-extend-native": "error",