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'
}
// the default is "en", not "int"
let parts
if (langCode === 'int') {
parts = [['get', 'name']]
} else {
parts = [
['get', `name_${langCode}`],
['get', `name:${langCode}`],
['get', 'name'],
const nameUnderscore = `name_${langCode}`
const nameColon = `name:${langCode}`
// Construct parts with exactly name_ and name: versions only (no int special case, no 'name' fallback)
const parts = [
['get', nameUnderscore],
['get', nameColon],
]
}
layer.layout['text-field'] = [
'case',
@@ -47,6 +44,22 @@ function modifyStyle({ style, langCode }) {
['concat', ['get', 'name:latin'], separator, ['get', 'name:nonlatin']],
['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', () => {
// Add default hash if not present
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)')
window.location.hash = '#es'
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 = '#en'
// The hashchange event will trigger applyLanguage()
} else {
applyLanguage()