Skip to content

Commit

Permalink
ugly hack to make dynamic theme work in styles, see maplibre/maplibre…
Browse files Browse the repository at this point in the history
  • Loading branch information
hiddewie committed Nov 2, 2024
1 parent ec5f452 commit 35e2599
Showing 1 changed file with 43 additions and 2 deletions.
45 changes: 43 additions & 2 deletions proxy/js/ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -471,12 +471,53 @@ const onStyleChange = changedStyle => {
// Change styles
map.setStyle(mapStyles[changedStyle], {
validate: false,
transformStyle: (previous, next) => {
let style = next;

// Apply theme to style
if (resolveTheme(configuration.theme ?? defaultConfiguration.theme) === 'dark') {
style = {
...style,
layers: style.layers.map(layer => {
if (layer.paint) {
if (layer.paint['text-color'] === 'black') {
layer.paint['text-color'] = 'white'
layer.paint['text-halo-color'] = 'black'
}
}

return layer;
})
}
}

return style;
},
});
legendMap.setStyle(legendStyles[changedStyle], {
validate: false,
transformStyle: (previous, next) => {
onStylesheetChange(next);
return next;
let style = next;

// Apply theme to style
if (resolveTheme(configuration.theme ?? defaultConfiguration.theme) === 'dark') {
style = {
...style,
layers: style.layers.map(layer => {
if (layer.paint) {
if (layer.paint['text-color'] === 'black') {
layer.paint['text-color'] = 'white'
layer.paint['text-halo-color'] = 'black'
}
}

return layer;
})
}
}

onStylesheetChange(style);
return style;
},
});

Expand Down

0 comments on commit 35e2599

Please sign in to comment.