更改 mapbox gl 中单个特征的样式

mal*_*olm 6 mapbox-gl mapbox-gl-js

在 mapbox gl 中突出显示多边形的示例使用第二层和过滤器功能。是否无法更改从 geojson 源绘制的 mapbox gl js 中单个要素/多边形的颜色?

https://www.mapbox.com/mapbox-gl-js/example/hover-styles/

Ste*_*ett 1

可以使用数据驱动的样式来设计单个要素的样式,该样式唯一地响应单个要素的属性。例如,如果您有一个带有id属性的点数据集,并且您希望 id 450 为黄色而不是蓝色。

{
  "id": "mypoints",
  "type": "circle",
  "paint": {
    "fill-color": {
      "property": "id",
      "type": "category",
      "stops": [[450, "yellow"]],
      "default": "blue"
    }
  }
}
Run Code Online (Sandbox Code Playgroud)

注意事项 1:“默认”功能尚未公开

注意事项 2:这仅适用于支持数据驱动功能的样式属性。