问题
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