Mapbox case expression

廉价感情. 提交于 2019-12-24 04:48:08

问题


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?


回答1:


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



来源:https://stackoverflow.com/questions/49601663/mapbox-case-expression

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!