How to use mapbox “case” expresion on nested properties?

天大地大妈咪最大 提交于 2019-12-11 05:08:49

问题


How to use nested value in order to use case == operator? Something like:

this.map.setPaintProperty("somelayer", "fill-color",
        ["case",
          ["==", ["properties:some_prop"], someval],
          "#34c0dd",
          "#499bbc"]

where properties is dict:

properties = {
some_prop: 1,
some_prop2: 2,
// and so on
}

I have tried ["properties.some_prop"] and ["properties"]["some_prop"] and that does not work as well.

And how to print that mapbox query like console.log or something?


回答1:


If properties is just the regular properties field on a GeoJSON object, then you don't mention it explicitly - all those fields are just accessed directly:

this.map.setPaintProperty("somelayer", "fill-color",
    ["case",
        ["==",  ["get", "some_prop"], someval], "#34c0dd",
         "#499bbc"
    ]);

Assuming #499bbc is the default colour you want.



来源:https://stackoverflow.com/questions/51134955/how-to-use-mapbox-case-expresion-on-nested-properties

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