This commit is contained in:
Zsolt Ero
2025-10-17 11:46:44 +02:00
parent 24e1e636b9
commit 8ce37a96b2

View File

@@ -29,17 +29,14 @@ function modifyStyle({ style, langCode }) {
separator = '\n' separator = '\n'
} }
// the default is "en", not "int" const nameUnderscore = `name_${langCode}`
let parts const nameColon = `name:${langCode}`
if (langCode === 'int') {
parts = [['get', 'name']] // Construct parts with exactly name_ and name: versions only (no int special case, no 'name' fallback)
} else { const parts = [
parts = [ ['get', nameUnderscore],
['get', `name_${langCode}`], ['get', nameColon],
['get', `name:${langCode}`], ]
['get', 'name'],
]
}
layer.layout['text-field'] = [ layer.layout['text-field'] = [
'case', 'case',
@@ -47,6 +44,22 @@ function modifyStyle({ style, langCode }) {
['concat', ['get', 'name:latin'], separator, ['get', 'name:nonlatin']], ['concat', ['get', 'name:latin'], separator, ['get', 'name:nonlatin']],
['coalesce', ...parts], ['coalesce', ...parts],
] ]
// Set color to red if both exist and are different, black otherwise
if (!layer.paint) layer.paint = {}
layer.paint['text-color'] = [
'case',
// If both name_ and name: exist and are different, show red
[
'all',
['has', nameUnderscore],
['has', nameColon],
['!=', ['get', nameUnderscore], ['get', nameColon]]
],
'#ff0000', // Red when different
'#000000' // Black when same or only one exists
]
} }
} }
@@ -62,8 +75,8 @@ function applyLanguage() {
map.on('load', () => { map.on('load', () => {
// Add default hash if not present // Add default hash if not present
if (!window.location.hash) { if (!window.location.hash) {
alert('To change the map language, modify the language code in the URL.\n\nExamples:\n• #en → English\n• #de → German\n• #fr → French\n• #es → Spanish\n• #int → International names\n\nDefault language set to: en (English)') alert('To change the map language, modify the language code in the URL #.\nLabels will be RED if name_xx and name:xx differ')
window.location.hash = '#es' window.location.hash = '#en'
// The hashchange event will trigger applyLanguage() // The hashchange event will trigger applyLanguage()
} else { } else {
applyLanguage() applyLanguage()