[openstreetmap/openstreetmap-website] Add kilometers/miles switch to directions (PR #5915)
Anton Khorev
notifications at github.com
Sun Apr 20 12:59:31 UTC 2025
@AntonKhorev commented on this pull request.
> + let distanceUnits = "km";
let downloadURL = null;
- function formatTotalDistance(m) {
- if (m < 1000) {
- return OSM.i18n.t("javascripts.directions.distance_m", { distance: Math.round(m) });
- } else if (m < 10000) {
- return OSM.i18n.t("javascripts.directions.distance_km", { distance: (m / 1000.0).toFixed(1) });
+ function translateDistanceUnits(m) {
+ if (distanceUnits === "km") {
+ return [m, "m", m / 1000, "km"];
} else {
- return OSM.i18n.t("javascripts.directions.distance_km", { distance: Math.round(m / 1000) });
+ return [m / 0.3048, "ft", m / 1609.344, "mi"];
}
}
- function formatStepDistance(m) {
- if (m < 5) {
+ function formatTotalDistance(minorValue, minorName, majorValue, majorName) {
+ const scope = "javascripts.directions.distance_in_units";
If we ignore that what's called a *formatter* here doesn't format anything, I'm not going to do functions/objects as values of km/mi preference until I decide where I'm storing that preference. Let's suppose the preference is persisted in a cookie. Certainly I'm not going to store a function or an object there.
--
Reply to this email directly or view it on GitHub:
https://github.com/openstreetmap/openstreetmap-website/pull/5915#discussion_r2051719175
You are receiving this because you are subscribed to this thread.
Message ID: <openstreetmap/openstreetmap-website/pull/5915/review/2780239951 at github.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.openstreetmap.org/pipermail/rails-dev/attachments/20250420/724665b6/attachment.htm>
More information about the rails-dev
mailing list