Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use mapbox "case" expresion on nested properties?

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?

like image 544
pregmatch Avatar asked Oct 30 '25 13:10

pregmatch


1 Answers

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.

like image 144
Steve Bennett Avatar answered Nov 01 '25 12:11

Steve Bennett