Open Infrastructure Map, a view of infrastructure data in OpenStreetMap
Use language detection for basemap labels
Russ Garrettb40d48fdccb9
diff --git a/web/src/openinframap.ts b/web/src/openinframap.tsindex 0be2bc3..3d7ee35 100644--- a/web/src/openinframap.ts+++ b/web/src/openinframap.ts@@ -96,7 +96,7 @@ export default class OpenInfraMap {)const url_hash = new URLHash(layer_switcher)- map_style.layers = style_base.concat(oim_layers, style_labels)+ map_style.layers = style_base.concat(oim_layers, style_labels())layer_switcher.setInitialVisibility(map_style)@@ -122,6 +122,10 @@ export default class OpenInfraMap {map.addImage(e.id, image.data, { pixelRatio: icon_ratio })})+ map.on('click', 'place_capital', (e) => {+ console.log(e.features)+ })+map.dragRotate.disable()map.touchZoomRotate.disableRotation()diff --git a/web/src/style/style_labels.ts b/web/src/style/style_labels.tsindex b8cb46f..cd62317 100644--- a/web/src/style/style_labels.ts+++ b/web/src/style/style_labels.ts@@ -1,248 +1,256 @@+import i18next from 'i18next'import { LayerSpecificationWithZIndex } from './types.ts'+import { coalesce, concat, get } from './stylehelpers.ts'+import { ExpressionSpecification } from 'maplibre-gl'const text_color = 'hsl(0, 0%, 20%)'const text_halo_color = 'rgb(242,243,240)'-const layers: LayerSpecificationWithZIndex[] = [- {- id: 'place_suburb',- type: 'symbol',- source: 'openmaptiles',- 'source-layer': 'place',- minzoom: 12,- maxzoom: 17,- filter: ['all', ['==', '$type', 'Point'], ['==', 'class', 'suburb']],- layout: {- 'text-anchor': 'center',- 'text-field': '{name:latin}\n{name:nonlatin}',- 'text-font': ['Noto Sans Regular'],- 'text-justify': 'center',- 'text-offset': [0.5, 0],- 'text-size': ['interpolate', ['linear'], ['zoom'], 12, 9, 17, 17]- },- paint: {- 'text-color': text_color,- 'text-halo-blur': 1,- 'text-halo-color': text_halo_color,- 'text-halo-width': 2- }- },- {- id: 'place_village',- type: 'symbol',- source: 'openmaptiles',- 'source-layer': 'place',- minzoom: 12,- maxzoom: 17,- filter: ['all', ['==', '$type', 'Point'], ['==', 'class', 'village']],- layout: {- 'text-anchor': 'center',- 'text-field': '{name:latin}\n{name:nonlatin}',- 'text-font': ['Noto Sans Regular'],- 'text-justify': 'center',- 'text-offset': [0.5, 0.2],- 'text-size': ['interpolate', ['linear'], ['zoom'], 12, 9, 17, 18]+function omtLabel(): ExpressionSpecification {+ const lang = i18next.language.split('-')[0]+ return concat(coalesce(get(`name:${lang}`), get('name:latin'), get('name')))+}++export default function layers(): LayerSpecificationWithZIndex[] {+ return [+ {+ id: 'place_suburb',+ type: 'symbol',+ source: 'openmaptiles',+ 'source-layer': 'place',+ minzoom: 12,+ maxzoom: 17,+ filter: ['all', ['==', '$type', 'Point'], ['==', 'class', 'suburb']],+ layout: {+ 'text-anchor': 'center',+ 'text-field': omtLabel(),+ 'text-font': ['Noto Sans Regular'],+ 'text-justify': 'center',+ 'text-offset': [0.5, 0],+ 'text-size': ['interpolate', ['linear'], ['zoom'], 12, 9, 17, 17]+ },+ paint: {+ 'text-color': text_color,+ 'text-halo-blur': 1,+ 'text-halo-color': text_halo_color,+ 'text-halo-width': 2+ }},- paint: {- 'text-color': text_color,- 'text-halo-blur': 1,- 'text-halo-color': text_halo_color,- 'text-halo-width': 2- }- },- {- id: 'place_town',- type: 'symbol',- source: 'openmaptiles',- 'source-layer': 'place',- minzoom: 10,- maxzoom: 15,- filter: ['all', ['==', '$type', 'Point'], ['==', 'class', 'town']],- layout: {- 'text-anchor': 'center',- 'text-field': '{name:latin}\n{name:nonlatin}',- 'text-font': ['Noto Sans Regular'],- 'text-justify': 'center',- 'text-offset': [0.5, 0.2],- 'text-size': ['interpolate', ['linear'], ['zoom'], 10, 9, 15, 18]+ {+ id: 'place_village',+ type: 'symbol',+ source: 'openmaptiles',+ 'source-layer': 'place',+ minzoom: 12,+ maxzoom: 17,+ filter: ['all', ['==', '$type', 'Point'], ['==', 'class', 'village']],+ layout: {+ 'text-anchor': 'center',+ 'text-field': omtLabel(),+ 'text-font': ['Noto Sans Regular'],+ 'text-justify': 'center',+ 'text-offset': [0.5, 0.2],+ 'text-size': ['interpolate', ['linear'], ['zoom'], 12, 9, 17, 18]+ },+ paint: {+ 'text-color': text_color,+ 'text-halo-blur': 1,+ 'text-halo-color': text_halo_color,+ 'text-halo-width': 2+ }},- paint: {- 'text-color': text_color,- 'text-halo-blur': 1,- 'text-halo-color': text_halo_color,- 'text-halo-width': 2- }- },- {- id: 'place_city',- type: 'symbol',- source: 'openmaptiles',- 'source-layer': 'place',- minzoom: 7.5,- maxzoom: 12,- filter: [- 'all',- ['==', '$type', 'Point'],- ['all', ['!=', 'capital', 2], ['==', 'class', 'city'], ['>', 'rank', 3]]- ],- layout: {- 'text-anchor': 'center',- 'text-field': '{name:latin}\n{name:nonlatin}',- 'text-font': ['Noto Sans Regular'],- 'text-justify': 'center',- 'text-offset': [0.5, 0.2],- 'text-size': 12,- visibility: 'visible'+ {+ id: 'place_town',+ type: 'symbol',+ source: 'openmaptiles',+ 'source-layer': 'place',+ minzoom: 10,+ maxzoom: 15,+ filter: ['all', ['==', '$type', 'Point'], ['==', 'class', 'town']],+ layout: {+ 'text-anchor': 'center',+ 'text-field': omtLabel(),+ 'text-font': ['Noto Sans Regular'],+ 'text-justify': 'center',+ 'text-offset': [0.5, 0.2],+ 'text-size': ['interpolate', ['linear'], ['zoom'], 10, 9, 15, 18]+ },+ paint: {+ 'text-color': text_color,+ 'text-halo-blur': 1,+ 'text-halo-color': text_halo_color,+ 'text-halo-width': 2+ }},- paint: {- 'text-color': text_color,- 'text-halo-blur': 1,- 'text-halo-color': text_halo_color,- 'text-halo-width': 2- }- },- {- id: 'place_capital',- type: 'symbol',- source: 'openmaptiles',- 'source-layer': 'place',- minzoom: 5.5,- maxzoom: 12,- filter: ['all', ['==', '$type', 'Point'], ['all', ['==', 'capital', 2], ['==', 'class', 'city']]],- layout: {- 'text-anchor': 'center',- 'text-field': '{name:latin}\n{name:nonlatin}',- 'text-font': ['Noto Sans Regular'],- 'text-justify': 'center',- 'text-offset': [0.5, 0.2],- 'text-size': 14,- visibility: 'visible'+ {+ id: 'place_city',+ type: 'symbol',+ source: 'openmaptiles',+ 'source-layer': 'place',+ minzoom: 7.5,+ maxzoom: 12,+ filter: [+ 'all',+ ['==', '$type', 'Point'],+ ['all', ['!=', 'capital', 2], ['==', 'class', 'city'], ['>', 'rank', 3]]+ ],+ layout: {+ 'text-anchor': 'center',+ 'text-field': omtLabel(),+ 'text-font': ['Noto Sans Regular'],+ 'text-justify': 'center',+ 'text-offset': [0.5, 0.2],+ 'text-size': 12,+ visibility: 'visible'+ },+ paint: {+ 'text-color': text_color,+ 'text-halo-blur': 1,+ 'text-halo-color': text_halo_color,+ 'text-halo-width': 2+ }},- paint: {- 'text-color': text_color,- 'text-halo-blur': 1,- 'text-halo-color': text_halo_color,- 'text-halo-width': 2- }- },- {- id: 'place_city_large',- type: 'symbol',- source: 'openmaptiles',- 'source-layer': 'place',- minzoom: 7,- maxzoom: 12,- filter: [- 'all',- ['==', '$type', 'Point'],- ['all', ['!=', 'capital', 2], ['<=', 'rank', 3], ['==', 'class', 'city']]- ],- layout: {- 'text-anchor': 'center',- 'text-field': '{name:latin}\n{name:nonlatin}',- 'text-font': ['Noto Sans Regular'],- 'text-justify': 'center',- 'text-offset': [0.5, 0.2],- 'text-size': 14,- visibility: 'visible'+ {+ id: 'place_capital',+ type: 'symbol',+ source: 'openmaptiles',+ 'source-layer': 'place',+ minzoom: 5.5,+ maxzoom: 12,+ filter: ['all', ['==', '$type', 'Point'], ['all', ['==', 'capital', 2], ['==', 'class', 'city']]],+ layout: {+ 'text-anchor': 'center',+ 'text-field': omtLabel(),+ 'text-font': ['Noto Sans Regular'],+ 'text-justify': 'center',+ 'text-offset': [0.5, 0.2],+ 'text-size': 14,+ visibility: 'visible'+ },+ paint: {+ 'text-color': text_color,+ 'text-halo-blur': 1,+ 'text-halo-color': text_halo_color,+ 'text-halo-width': 2+ }},- paint: {- 'text-color': text_color,- 'text-halo-blur': 1,- 'text-halo-color': text_halo_color,- 'text-halo-width': 2- }- },- {- id: 'place_state',- type: 'symbol',- source: 'openmaptiles',- 'source-layer': 'place',- minzoom: 5,- maxzoom: 12,- filter: ['all', ['==', '$type', 'Point'], ['==', 'class', 'state']],- layout: {- 'text-field': '{name:latin}\n{name:nonlatin}',- 'text-font': ['Noto Sans Regular'],- 'text-size': 15,- visibility: 'visible'+ {+ id: 'place_city_large',+ type: 'symbol',+ source: 'openmaptiles',+ 'source-layer': 'place',+ minzoom: 7,+ maxzoom: 12,+ filter: [+ 'all',+ ['==', '$type', 'Point'],+ ['all', ['!=', 'capital', 2], ['<=', 'rank', 3], ['==', 'class', 'city']]+ ],+ layout: {+ 'text-anchor': 'center',+ 'text-field': omtLabel(),+ 'text-font': ['Noto Sans Regular'],+ 'text-justify': 'center',+ 'text-offset': [0.5, 0.2],+ 'text-size': 14,+ visibility: 'visible'+ },+ paint: {+ 'text-color': text_color,+ 'text-halo-blur': 1,+ 'text-halo-color': text_halo_color,+ 'text-halo-width': 2+ }},- paint: {- 'text-color': text_color,- 'text-halo-blur': 1,- 'text-halo-color': text_halo_color,- 'text-halo-width': 2- }- },- {- id: 'place_country_other',- type: 'symbol',- source: 'openmaptiles',- 'source-layer': 'place',- maxzoom: 8,- filter: ['all', ['==', '$type', 'Point'], ['==', 'class', 'country'], ['!has', 'iso_a2']],- layout: {- 'text-field': ['case', ['has', 'name:en'], ['get', 'name:en'], ['get', 'name:latin']],- 'text-font': ['Metropolis Light Italic', 'Noto Sans Regular Italic'],- 'text-size': ['interpolate', ['linear'], ['zoom'], 0, 9, 6, 15]+ {+ id: 'place_state',+ type: 'symbol',+ source: 'openmaptiles',+ 'source-layer': 'place',+ minzoom: 5,+ maxzoom: 12,+ filter: ['all', ['==', '$type', 'Point'], ['==', 'class', 'state']],+ layout: {+ 'text-field': omtLabel(),+ 'text-font': ['Noto Sans Regular'],+ 'text-size': 15,+ visibility: 'visible'+ },+ paint: {+ 'text-color': text_color,+ 'text-halo-blur': 1,+ 'text-halo-color': text_halo_color,+ 'text-halo-width': 2+ }},- paint: {- 'text-color': text_color,- 'text-halo-color': text_halo_color,- 'text-halo-width': 2- }- },- {- id: 'place_country_minor',- type: 'symbol',- source: 'openmaptiles',- 'source-layer': 'place',- minzoom: 3,- maxzoom: 8,- filter: [- 'all',- ['==', '$type', 'Point'],- ['==', 'class', 'country'],- ['>=', 'rank', 2],- ['has', 'iso_a2']- ],- layout: {- 'text-field': ['case', ['has', 'name:en'], ['get', 'name:en'], ['get', 'name:latin']],- 'text-font': ['Noto Sans Regular'],- 'text-size': ['interpolate', ['linear'], ['zoom'], 0, 10, 6, 12]+ {+ id: 'place_country_other',+ type: 'symbol',+ source: 'openmaptiles',+ 'source-layer': 'place',+ maxzoom: 8,+ filter: ['all', ['==', '$type', 'Point'], ['==', 'class', 'country'], ['!has', 'iso_a2']],+ layout: {+ 'text-field': omtLabel(),+ 'text-font': ['Metropolis Light Italic', 'Noto Sans Regular Italic'],+ 'text-size': ['interpolate', ['linear'], ['zoom'], 0, 9, 6, 15]+ },+ paint: {+ 'text-color': text_color,+ 'text-halo-color': text_halo_color,+ 'text-halo-width': 2+ }},- paint: {- 'text-color': text_color,- 'text-halo-color': text_halo_color,- 'text-halo-width': 2- }- },- {- id: 'place_country_major',- type: 'symbol',- source: 'openmaptiles',- 'source-layer': 'place',- minzoom: 3,- maxzoom: 5,- filter: [- 'all',- ['==', '$type', 'Point'],- ['<=', 'rank', 1],- ['==', 'class', 'country'],- ['has', 'iso_a2']- ],- layout: {- 'text-anchor': 'center',- 'text-field': ['case', ['has', 'name:en'], ['get', 'name:en'], ['get', 'name:latin']],- 'text-font': ['Noto Sans Regular'],- 'text-size': ['interpolate', ['linear'], ['zoom'], 0, 10, 3, 12, 4, 14]+ {+ id: 'place_country_minor',+ type: 'symbol',+ source: 'openmaptiles',+ 'source-layer': 'place',+ minzoom: 3,+ maxzoom: 8,+ filter: [+ 'all',+ ['==', '$type', 'Point'],+ ['==', 'class', 'country'],+ ['>=', 'rank', 2],+ ['has', 'iso_a2']+ ],+ layout: {+ 'text-field': omtLabel(),+ 'text-font': ['Noto Sans Regular'],+ 'text-size': ['interpolate', ['linear'], ['zoom'], 0, 10, 6, 12]+ },+ paint: {+ 'text-color': text_color,+ 'text-halo-color': text_halo_color,+ 'text-halo-width': 2+ }},- paint: {- 'text-color': text_color,- 'text-halo-color': text_halo_color,- 'text-halo-width': 2.4+ {+ id: 'place_country_major',+ type: 'symbol',+ source: 'openmaptiles',+ 'source-layer': 'place',+ minzoom: 3,+ maxzoom: 5,+ filter: [+ 'all',+ ['==', '$type', 'Point'],+ ['<=', 'rank', 1],+ ['==', 'class', 'country'],+ ['has', 'iso_a2']+ ],+ layout: {+ 'text-anchor': 'center',+ 'text-field': omtLabel(),+ 'text-font': ['Noto Sans Regular'],+ 'text-size': ['interpolate', ['linear'], ['zoom'], 0, 10, 3, 12, 4, 14]+ },+ paint: {+ 'text-color': text_color,+ 'text-halo-color': text_halo_color,+ 'text-halo-width': 2.4+ }}- }-]--export default layers+ ]+}