如何在嵌套属性上使用 mapbox "case" 表达式?

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

如何使用嵌套值来使用 case == 运算符?类似于:

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

其中属性是字典:

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

我已经尝试了 ["properties.some_prop"] 和 ["properties"]["some_prop"],但还是不行。

以及如何打印像 console.log 之类的 mapbox 查询?

如果 properties 只是 GeoJSON 对象上的常规 properties 字段,那么您无需明确提及它 - 所有这些字段都可以直接访问:

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

假设 #499bbc 是您想要的默认颜色。