Files
iD/modules/ui/feature_info.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

55 lines
1.6 KiB
JavaScript

import { event as d3_event } from 'd3-selection';
import { t } from '../core/localizer';
import { uiTooltip } from './tooltip';
export function uiFeatureInfo(context) {
function update(selection) {
var features = context.features();
var stats = features.stats();
var count = 0;
var hiddenList = features.hidden().map(function(k) {
if (stats[k]) {
count += stats[k];
return String(stats[k]) + ' ' + t('feature.' + k + '.description');
}
}).filter(Boolean);
selection.html('');
if (hiddenList.length) {
var tooltipBehavior = uiTooltip()
.placement('top')
.title(function() {
return hiddenList.join('<br/>');
});
selection.append('a')
.attr('class', 'chip')
.attr('href', '#')
.attr('tabindex', -1)
.html(t('feature_info.hidden_warning', { count: count }))
.call(tooltipBehavior)
.on('click', function() {
tooltipBehavior.hide();
d3_event.preventDefault();
// open the Map Data pane
context.ui().togglePanes(context.container().select('.map-panes .map-data-pane'));
});
}
selection
.classed('hide', !hiddenList.length);
}
return function(selection) {
update(selection);
context.features().on('change.feature_info', function() {
update(selection);
});
};
}