Files
iD/modules/ui/panels/location.js
Quincy Morgan a1af118f0e Ensure locales and presets are loaded before the UI loads (close #7406)
Consolidate localization behavior and init to a coreLocalizer function and singleton
Explicitly support `en-US` locale
Rename coreData to coreFileFetcher and export a singleton rather than using a property of coreContext
Add `apiConnections` property of coreContext to simplify adding a source switcher
Replace some init functions with re-callable, promise-supporting `ensureLoaded` functions
Make coreContext itself load the UI if a container has been specified at init time
Fix code tests
2020-03-31 12:23:31 -07:00

77 lines
2.0 KiB
JavaScript

import _debounce from 'lodash-es/debounce';
import { decimalCoordinatePair, dmsCoordinatePair } from '../../util/units';
import { t } from '../../core/localizer';
import { services } from '../../services';
export function uiPanelLocation(context) {
var currLocation = '';
function redraw(selection) {
selection.html('');
var list = selection
.append('ul');
// Mouse coordinates
var coord = context.map().mouseCoordinates();
if (coord.some(isNaN)) {
coord = context.map().center();
}
list
.append('li')
.text(dmsCoordinatePair(coord))
.append('li')
.text(decimalCoordinatePair(coord));
// Location Info
selection
.append('div')
.attr('class', 'location-info')
.text(currLocation || ' ');
debouncedGetLocation(selection, coord);
}
var debouncedGetLocation = _debounce(getLocation, 250);
function getLocation(selection, coord) {
if (!services.geocoder) {
currLocation = t('info_panels.location.unknown_location');
selection.selectAll('.location-info')
.text(currLocation);
} else {
services.geocoder.reverse(coord, function(err, result) {
currLocation = result ? result.display_name : t('info_panels.location.unknown_location');
selection.selectAll('.location-info')
.text(currLocation);
});
}
}
var panel = function(selection) {
selection.call(redraw);
context.surface()
.on('mousemove.info-location', function() {
selection.call(redraw);
});
};
panel.off = function() {
context.surface()
.on('mousemove.info-location', null);
};
panel.id = 'location';
panel.title = t('info_panels.location.title');
panel.key = t('info_panels.location.key');
return panel;
}