Made scale legend localizable

This commit is contained in:
Minh Nguyễn
2018-01-09 00:10:19 -08:00
parent e661281e38
commit 1d8d7a74a3
3 changed files with 20 additions and 6 deletions
+9 -6
View File
@@ -1,10 +1,12 @@
import { geoLonToMeters, geoMetersToLon } from '../geo';
import { t } from '../util/locale';
import { utilDetect } from '../util/detect';
export function uiScale(context) {
var projection = context.projection,
isImperial = (utilDetect().locale.toLowerCase() === 'en-us'),
locale = utilDetect().locale,
isImperial = (locale.toLowerCase() === 'en-us'),
maxLength = 180,
tickHeight = 8;
@@ -14,7 +16,7 @@ export function uiScale(context) {
conversion = (isImperial ? 3.28084 : 1),
dist = geoLonToMeters(loc2[0] - loc1[0], lat) * conversion,
scale = { dist: 0, px: 0, text: '' },
buckets, i, val, dLon;
buckets, i, val, dLon, textKey;
if (isImperial) {
buckets = [5280000, 528000, 52800, 5280, 500, 50, 5, 1];
@@ -39,18 +41,19 @@ export function uiScale(context) {
if (isImperial) {
if (scale.dist >= 5280) {
scale.dist /= 5280;
scale.text = String(scale.dist) + ' mi';
textKey = 'scale.miles';
} else {
scale.text = String(scale.dist) + ' ft';
textKey = 'scale.feet';
}
} else {
if (scale.dist >= 1000) {
scale.dist /= 1000;
scale.text = String(scale.dist) + ' km';
textKey = 'scale.kilometers';
} else {
scale.text = String(scale.dist) + ' m';
textKey = 'scale.meters';
}
}
scale.text = t(textKey, { quantity: scale.dist.toLocaleString(locale) });
return scale;
}