在mapbox gl中更改单个功能的样式 [英] Change style of single feature in mapbox gl

查看:516
本文介绍了在mapbox gl中更改单个功能的样式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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?

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

推荐答案

可以使用数据驱动样式来对单个要素进行样式设置,该样式可对单个要素的属性做出唯一响应.例如,如果您的点数据集具有id属性,并且您希望ID 450为黄色而不是蓝色.

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"
    }
  }
}

注意事项1:默认"功能是尚未公开可用.

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

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

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

这篇关于在mapbox gl中更改单个功能的样式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆