From fe8c218fb3bdc390554594ec4eadaf2f955ba4d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Minh=20Nguy=E1=BB=85n?= Date: Tue, 9 Jan 2018 02:23:13 -0800 Subject: [PATCH] Localized geocoded coordinate formatting --- modules/ui/feature_list.js | 3 ++- modules/util/units.js | 17 +++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/modules/ui/feature_list.js b/modules/ui/feature_list.js index d5ed9330b..457940143 100644 --- a/modules/ui/feature_list.js +++ b/modules/ui/feature_list.js @@ -7,6 +7,7 @@ import { d3keybinding as d3_keybinding } from '../lib/d3.keybinding.js'; import * as sexagesimal from '@mapbox/sexagesimal'; import { t } from '../util/locale'; +import { displayCoordinatePair } from '../util/units'; import { geoExtent, geoChooseEdge } from '../geo'; import { modeSelect } from '../modes'; import { osmEntity } from '../osm'; @@ -143,7 +144,7 @@ export function uiFeatureList(context) { id: -1, geometry: 'point', type: t('inspector.location'), - name: loc[0].toFixed(6) + ', ' + loc[1].toFixed(6), + name: displayCoordinatePair([loc[1], loc[0]]), location: loc }); } diff --git a/modules/util/units.js b/modules/util/units.js index 7ea5a2304..c7e2ff1da 100644 --- a/modules/util/units.js +++ b/modules/util/units.js @@ -4,6 +4,12 @@ import { utilDetect } from 'detect'; var OSM_PRECISION = 7; var locale = utilDetect().locale; +/** + * Returns a localized representation of the given length measurement. + * + * @param {Number} m area in meters + * @param {Boolean} isImperial true for U.S. customary units; false for metric + */ export function displayLength(m, isImperial) { var d = m * (isImperial ? 3.28084 : 1), unit; @@ -29,6 +35,12 @@ export function displayLength(m, isImperial) { }); } +/** + * Returns a localized representation of the given area measurement. + * + * @param {Number} m2 area in square meters + * @param {Boolean} isImperial true for U.S. customary units; false for metric + */ export function displayArea(m2, isImperial) { var d = m2 * (isImperial ? 10.7639111056 : 1), d1, d2, unit1, unit2, area; @@ -87,6 +99,11 @@ function clamp(x, min, max) { return Math.max(min, Math.min(x, max)); } +/** + * Returns a human-readable representation of the given coordinate pair. + * + * @param {Array} coord longitude and latitude + */ export function displayCoordinatePair(coord) { return t('units.coordinate_pair', { latitude: clamp(coord[1], -90, 90).toLocaleString(locale, { maximumFractionDigits: OSM_PRECISION }),