Skip to content

Open Infrastructure Map, a view of infrastructure data in OpenStreetMap

Use localised names on web map

Russ Garrett593ff7e8f123
diff --git a/web/src/infopopup.css b/web/src/infopopup.css
index a3d02ff..77c021f 100644
--- a/web/src/infopopup.css
+++ b/web/src/infopopup.css
@@ -6,9 +6,27 @@ table.item_info th {
max-width: 350px !important;
}
+.mapboxgl-popup .nameContainer {
+ margin-bottom: 5px;
+}
+
.mapboxgl-popup h3 {
margin-top: 0px;
- margin-bottom: 5px;
+ margin-bottom: 0px;
+}
+
+.mapboxgl-popup h4::before {
+ content: "("
+}
+
+.mapboxgl-popup h4::after {
+ content: ")"
+}
+
+.mapboxgl-popup h4 {
+ font-weight: normal;
+ margin-top: 0px;
+ margin-bottom: 0px;
}
.wikidata_image {
diff --git a/web/src/infopopup.js b/web/src/infopopup.js
index 23fa0e4..79ebf08 100644
--- a/web/src/infopopup.js
+++ b/web/src/infopopup.js
@@ -3,6 +3,7 @@ import './infopopup.css';
import mapboxgl from 'maplibre-gl';
import titleCase from 'title-case';
import browserLanguage from 'in-browser-language';
+import {local_name_tags} from './l10n.js';
import {el, text, mount, unmount, setChildren, setStyle} from 'redom';
const hidden_keys = [
@@ -117,6 +118,30 @@ class InfoPopup {
return el('tr', el('th', key), el('td', value));
}
+ nameTags(feature) {
+ let title_text = '';
+
+ for (const tag of local_name_tags) {
+ if (feature.properties[tag]) {
+ title_text = feature.properties[tag];
+ break;
+ }
+ }
+
+ if (!title_text) {
+ title_text = feature.layer['id'];
+ }
+
+ let container = el('div.nameContainer', el('h3', title_text));
+
+ // If we're showing a translated name, also show the name tag
+ if (feature.properties.name && title_text != feature.properties.name) {
+ mount(container, el('h4', feature.properties.name));
+ }
+
+ return container;
+ }
+
popupHtml(feature) {
let attrs_table = el('table', {class: 'item_info'});
setChildren(
@@ -128,13 +153,6 @@ class InfoPopup {
),
);
- let title_text = '';
- if (feature.properties['name']) {
- title_text = feature.properties['name'];
- } else {
- title_text = feature.layer['id'];
- }
-
let links_container = el('div');
if (feature.properties['osm_id']) {
@@ -168,7 +186,7 @@ class InfoPopup {
let content = el(
'div',
- el('h3', title_text),
+ this.nameTags(feature),
links_container,
wikidata_div,
attrs_table,
diff --git a/web/src/l10n.js b/web/src/l10n.js
new file mode 100644
index 0000000..1e7ea7a
--- /dev/null
+++ b/web/src/l10n.js
@@ -0,0 +1,15 @@
+import browserLanguage from "in-browser-language";
+
+/* List of supported languages in the OpenInfraMap layer.
+ * This should be kept up to date with the list in tegola/layers.yml.
+ */
+const layer_supported_languages = ["en", "es", "de", "fr", "hi", "ur", "zh", "ru", "pt", "ja"];
+
+/* List of name tags to check, in order */
+const local_name_tags = browserLanguage
+ .list()
+ .filter(code => layer_supported_languages.includes(code))
+ .map(code => `name_${code}`)
+ .concat(['name']);
+
+export { layer_supported_languages, local_name_tags };
diff --git a/web/src/style/style_oim_power.js b/web/src/style/style_oim_power.js
index 0342967..e899650 100644
--- a/web/src/style/style_oim_power.js
+++ b/web/src/style/style_oim_power.js
@@ -1,5 +1,5 @@
import {text_paint, underground_p} from './style_oim_common.js';
-// OpenInfraMap layers
+import {local_name_tags} from '../l10n.js';
const voltage_scale = [
[null, '#7A7A85'],
@@ -318,15 +318,17 @@ const pretty_output = ['case',
['concat', ['round', ['*', output, 1000]], ' kW']
];
+const local_name = ['coalesce'].concat(local_name_tags.map(tag => ['get', tag]))
+
const plant_label = ['step', ['zoom'],
- ['concat', ['get', 'name']],
+ ['concat', local_name],
9,
['case',
['all', ['!', ['has', 'name']], ['has', 'output']],
['concat', pretty_output, construction_label],
['has', 'output'],
- ['concat', ['get', 'name'], ' \n', pretty_output, '\n', construction_label],
- ['get', 'name']
+ ['concat', local_name, ' \n', pretty_output, '\n', construction_label],
+ local_name
],
];
@@ -384,10 +386,10 @@ const line_voltage = [
const line_label = [
'case',
- ['all', ['has', 'voltage'], ['has', 'name'], ['!=', ['get', 'name'], '']],
+ ['all', ['has', 'voltage'], ['has', 'name'], ['!=', local_name, '']],
[
'concat',
- ['get', 'name'],
+ local_name,
' (',
line_voltage,
freq,
@@ -396,22 +398,22 @@ const line_label = [
],
['has', 'voltage'],
['concat', line_voltage, freq, construction_label],
- ['get', 'name'],
+ local_name,
];
const substation_label_detail = [
'case',
- ['all', ['!=', ['get', 'name'], ''], ['has', 'voltage']],
+ ['all', ['!=', local_name, ''], ['has', 'voltage']],
[
'concat',
- ['get', 'name'],
+ local_name,
' ',
voltage,
' kV',
freq,
construction_label,
],
- ['all', ['==', ['get', 'name'], ''], ['has', 'voltage']],
+ ['all', ['==', local_name, ''], ['has', 'voltage']],
[
'concat',
'Substation ',
@@ -420,13 +422,13 @@ const substation_label_detail = [
freq,
construction_label,
],
- ['get', 'name'],
+ local_name,
];
const substation_label = [
'step',
['zoom'],
- ['get', 'name'],
+ local_name,
12,
substation_label_detail,
];
diff --git a/web/src/style/style_oim_telecoms.js b/web/src/style/style_oim_telecoms.js
index 7b96116..164a6d0 100644
--- a/web/src/style/style_oim_telecoms.js
+++ b/web/src/style/style_oim_telecoms.js
@@ -1,4 +1,6 @@
import {text_paint, operator_text} from './style_oim_common.js';
+import {local_name_tags} from '../l10n.js';
+const local_name = ['coalesce'].concat(local_name_tags.map(tag => ['get', tag]));
const layers = [
{
@@ -91,7 +93,7 @@ const layers = [
'source-layer': 'telecoms_communication_line',
paint: text_paint,
layout: {
- 'text-field': '{name}',
+ 'text-field': local_name,
'symbol-placement': 'line',
'symbol-spacing': 400,
'text-size': 10,