localization of OpenMapTiles styles

This commit is contained in:
vcoppe
2026-05-28 19:15:01 +02:00
parent 1e6a12eeda
commit 6a9d30e8ea
+32 -15
View File
@@ -225,21 +225,38 @@ export class StyleManager {
} }
if (layer.type === 'symbol' && layer.layout && layer.layout['text-field']) { if (layer.type === 'symbol' && layer.layout && layer.layout['text-field']) {
const textField = layer.layout['text-field']; const textField = layer.layout['text-field'];
if ( if (Array.isArray(textField)) {
Array.isArray(textField) && if (
textField.length == 4 && textField.length == 4 &&
Array.isArray(textField[3]) && Array.isArray(textField[3]) &&
textField[3][0] === 'coalesce' && textField[3][0] === 'coalesce' &&
Array.isArray(textField[3][1]) && Array.isArray(textField[3][1]) &&
textField[3][1][0] === 'get' && textField[3][1][0] === 'get' &&
typeof textField[3][1][1] === 'string' && typeof textField[3][1][1] === 'string' &&
textField[3][1][1].startsWith('name') textField[3][1][1].startsWith('name')
) { ) {
layer.layout['text-field'] = [ // OpenFreeMap styles
'coalesce', layer.layout['text-field'] = [
['get', `name:${i18n.lang}`], 'coalesce',
['get', 'name'], ['get', `name:${i18n.lang}`],
]; ['get', 'name'],
];
}
if (
textField.length == 3 &&
textField[0] === 'coalesce' &&
Array.isArray(textField[1]) &&
textField[1][0] === 'get' &&
typeof textField[1][1] === 'string' &&
textField[1][1].startsWith('name')
) {
// OpenMapTiles styles
layer.layout['text-field'] = [
'coalesce',
['get', `name:${i18n.lang}`],
['get', 'name'],
];
}
} }
} }
style.layers.push(layer); style.layers.push(layer);