mirror of
https://github.com/FoggedLens/iD.git
synced 2026-05-16 13:59:27 +02:00
DMS coordinates
This commit is contained in:
@@ -1067,4 +1067,12 @@ en:
|
||||
square_kilometers: "{quantity} km²"
|
||||
hectares: "{quantity} ha"
|
||||
area_pair: "{area1} ({area2})"
|
||||
arcdegrees: "{quantity}°"
|
||||
arcminutes: "{quantity}′"
|
||||
arcseconds: "{quantity}″"
|
||||
north: "N"
|
||||
south: "S"
|
||||
east: "E"
|
||||
west: "W"
|
||||
coordinate: "{coordinate}{direction}"
|
||||
coordinate_pair: "{latitude}, {longitude}"
|
||||
|
||||
Vendored
+8
@@ -1233,6 +1233,14 @@
|
||||
"square_kilometers": "{quantity} km²",
|
||||
"hectares": "{quantity} ha",
|
||||
"area_pair": "{area1} ({area2})",
|
||||
"arcdegrees": "{quantity}°",
|
||||
"arcminutes": "{quantity}′",
|
||||
"arcseconds": "{quantity}″",
|
||||
"north": "N",
|
||||
"south": "S",
|
||||
"east": "E",
|
||||
"west": "W",
|
||||
"coordinate": "{coordinate}{direction}",
|
||||
"coordinate_pair": "{latitude}, {longitude}"
|
||||
},
|
||||
"presets": {
|
||||
|
||||
@@ -7,7 +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 { dmsCoordinatePair } from '../util/units';
|
||||
import { geoExtent, geoChooseEdge } from '../geo';
|
||||
import { modeSelect } from '../modes';
|
||||
import { osmEntity } from '../osm';
|
||||
@@ -144,7 +144,7 @@ export function uiFeatureList(context) {
|
||||
id: -1,
|
||||
geometry: 'point',
|
||||
type: t('inspector.location'),
|
||||
name: displayCoordinatePair([loc[1], loc[0]]),
|
||||
name: dmsCoordinatePair([loc[1], loc[0]]),
|
||||
location: loc
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import _debounce from 'lodash-es/debounce';
|
||||
|
||||
import { displayCoordinatePair } from '../../util/units';
|
||||
import { decimalCoordinatePair, dmsCoordinatePair } from '../../util/units';
|
||||
import { t } from '../../util/locale';
|
||||
import { services } from '../../services';
|
||||
|
||||
@@ -21,11 +21,11 @@ export function uiPanelLocation(context) {
|
||||
coord = context.map().center();
|
||||
}
|
||||
|
||||
var coordStr = displayCoordinatePair(coord);
|
||||
|
||||
list
|
||||
.append('li')
|
||||
.text(coordStr);
|
||||
.text(dmsCoordinatePair(coord))
|
||||
.append('li')
|
||||
.text(decimalCoordinatePair(coord));
|
||||
|
||||
// Location Info
|
||||
selection
|
||||
|
||||
@@ -8,7 +8,7 @@ import {
|
||||
} from 'd3-geo';
|
||||
|
||||
import { t } from '../../util/locale';
|
||||
import { displayArea, displayLength, displayCoordinatePair } from '../../util/units';
|
||||
import { displayArea, displayLength, decimalCoordinatePair, dmsCoordinatePair } from '../../util/units';
|
||||
import { geoExtent } from '../../geo';
|
||||
import { utilDetect } from '../../util/detect';
|
||||
|
||||
@@ -78,14 +78,17 @@ export function uiPanelMeasurement(context) {
|
||||
|
||||
var list = selection
|
||||
.append('ul');
|
||||
var coordItem;
|
||||
|
||||
// multiple features, just display extent center..
|
||||
if (!singular) {
|
||||
list
|
||||
coordItem = list
|
||||
.append('li')
|
||||
.text(t('info_panels.measurement.center') + ':')
|
||||
.append('span')
|
||||
.text(displayCoordinatePair(center));
|
||||
.text(t('info_panels.measurement.center') + ':');
|
||||
coordItem.append('span')
|
||||
.text(dmsCoordinatePair(center));
|
||||
coordItem.append('span')
|
||||
.text(decimalCoordinatePair(center));
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -132,11 +135,13 @@ export function uiPanelMeasurement(context) {
|
||||
.append('span')
|
||||
.text(displayLength(length, isImperial));
|
||||
|
||||
list
|
||||
coordItem = list
|
||||
.append('li')
|
||||
.text(t('info_panels.measurement.centroid') + ':')
|
||||
.append('span')
|
||||
.text(displayCoordinatePair(centroid));
|
||||
.text(t('info_panels.measurement.centroid') + ':');
|
||||
coordItem.append('span')
|
||||
.text(dmsCoordinatePair(centroid));
|
||||
coordItem.append('span')
|
||||
.text(decimalCoordinatePair(centroid));
|
||||
|
||||
var toggle = isImperial ? 'imperial' : 'metric';
|
||||
|
||||
@@ -160,11 +165,13 @@ export function uiPanelMeasurement(context) {
|
||||
.append('span')
|
||||
.text(t('geometry.' + geometry));
|
||||
|
||||
list
|
||||
coordItem = list
|
||||
.append('li')
|
||||
.text(centerLabel + ':')
|
||||
.append('span')
|
||||
.text(displayCoordinatePair(center));
|
||||
.text(centerLabel + ':');
|
||||
coordItem.append('span')
|
||||
.text(dmsCoordinatePair(center));
|
||||
coordItem.append('span')
|
||||
.text(decimalCoordinatePair(center));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+46
-3
@@ -99,13 +99,56 @@ function clamp(x, min, max) {
|
||||
return Math.max(min, Math.min(x, max));
|
||||
}
|
||||
|
||||
function displayCoordinate(deg, pos, neg) {
|
||||
var min = (Math.abs(deg) - Math.floor(Math.abs(deg))) * 60,
|
||||
sec = (min - Math.floor(min)) * 60,
|
||||
displayDegrees = t('units.arcdegrees', {
|
||||
quantity: Math.floor(Math.abs(deg)).toLocaleString(locale)
|
||||
}),
|
||||
displayCoordinate;
|
||||
|
||||
if (Math.floor(sec) > 0) {
|
||||
displayCoordinate = displayDegrees +
|
||||
t('units.arcminutes', { quantity: Math.floor(min).toLocaleString(locale) }) +
|
||||
t('units.arcseconds', { quantity: Math.round(sec).toLocaleString(locale) });
|
||||
} else if (Math.floor(min) > 0) {
|
||||
displayCoordinate = displayDegrees +
|
||||
t('units.arcminutes', { quantity: Math.round(min).toLocaleString(locale) });
|
||||
} else {
|
||||
displayCoordinate = t('units.arcdegrees', {
|
||||
quantity: Math.round(Math.abs(deg)).toLocaleString(locale)
|
||||
});
|
||||
}
|
||||
|
||||
if (deg === 0) {
|
||||
return displayCoordinate;
|
||||
} else {
|
||||
return t('units.coordinate', {
|
||||
coordinate: displayCoordinate,
|
||||
direction: t('units.' + (deg > 0 ? pos : neg))
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a human-readable representation of the given coordinate pair.
|
||||
* Returns given coordinate pair in degree-minute-second format.
|
||||
*
|
||||
* @param {Array<Number>} coord longitude and latitude
|
||||
*/
|
||||
export function displayCoordinatePair(coord) {
|
||||
return t('units.coordinate_pair', {
|
||||
export function dmsCoordinatePair(coord) {
|
||||
return t('units.coordinate_pair', {
|
||||
latitude: displayCoordinate(clamp(coord[1], -90, 90), 'north', 'south'),
|
||||
longitude: displayCoordinate(wrap(coord[0], -180, 180), 'east', 'west')
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the given coordinate pair in decimal format.
|
||||
*
|
||||
* @param {Array<Number>} coord longitude and latitude
|
||||
*/
|
||||
export function decimalCoordinatePair(coord) {
|
||||
return t('units.coordinate_pair', {
|
||||
latitude: clamp(coord[1], -90, 90).toLocaleString(locale, { maximumFractionDigits: OSM_PRECISION }),
|
||||
longitude: wrap(coord[0], -180, 180).toLocaleString(locale, { maximumFractionDigits: OSM_PRECISION })
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user