Change style of single feature in mapbox gl

百般思念 提交于 2019-12-01 05:08:48

问题


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 js, drawn from geojson source?

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


回答1:


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.



来源:https://stackoverflow.com/questions/42282533/change-style-of-single-feature-in-mapbox-gl

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!