Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mapbox case expression

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?

like image 529
Konrad Woj Avatar asked Apr 01 '18 19:04

Konrad Woj


1 Answers

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

like image 140
Scarysize Avatar answered Oct 25 '22 22:10

Scarysize