Change style of single feature in mapbox gl

后端 未结 1 536
暖寄归人
暖寄归人 2021-01-13 06:09

The examples for highlighting polygons in mapbox gl use a second layer and a filter function. Is it not possible to change the color of a single feature/polygon in mapbox gl

相关标签:
1条回答
  • 2021-01-13 06:49

    It's possible to style a single feature using a data driven style that responds uniquely to an attribute of a single feature. For instance, if you have a point dataset with an id attribute and you want id 450 to be yellow instead of blue.

    {
      "id": "mypoints",
      "type": "circle",
      "paint": {
        "fill-color": {
          "property": "id",
          "type": "category",
          "stops": [[450, "yellow"]],
          "default": "blue"
        }
      }
    }
    

    Caveat 1: the "default" feature is not publicly available yet.

    Caveat 2: This only works for style properties that support data-driven functions.

    0 讨论(0)
提交回复
热议问题