i try to style my mapbox layer using case expression:
const max_expr = ['max', ['get', 'POLY_COLOUR_CODE_D'], ['get', 'POLY_COLOUR_CODE_BW'], ['get', 'POLY_COLOUR_CODE_A']];
'paint': {
'fill-color': ['case', ['==', max_expr, 1], 'green', ['==', max_expr, 2], 'yellow',
['==', max_expr, 3], 'red', ['==', max_expr, 4], 'red']
}
but i get following weird error: paint.fill-color: Expected an odd number of arguments. Do you have any idea how to fix this?
You are probably just missing a default value in your case
expression:
[
'case',
['==', max_expr, 1],
'green',
['==', max_expr, 2],
'yellow',
['==', max_expr, 3],
'red',
['==', max_expr, 4],
'red',
<default>
];
It's not super obvious, but the documentation shows that a default is not optional: https://www.mapbox.com/mapbox-gl-js/style-spec/#expressions-case
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With