更改mapbox群集映射中的文本颜色

时间:2017-06-26 22:42:37

标签: javascript mapbox mapbox-gl

我正在尝试更改地图集群集地图中的文字颜色(https://www.mapbox.com/mapbox-gl-js/example/cluster/),但我无法弄清楚如何。

以下是相关代码:

map.addLayer({
    id: "cluster-count",
    type: "symbol",
    source: "grundbuch",
    filter: ["has", "point_count"],
    layout: {
        "text-field": "{point_count_abbreviated}",
        "text-font": ["DIN Offc Pro Medium", "Arial Unicode MS Bold"],
        "text-size": 12
    }
});

有人知道怎么做吗?我想将数字标签更改为白色。

1 个答案:

答案 0 :(得分:9)

要更改地图图层中的文字颜色,您需要使用"paint"属性设置text-color属性REF:

paint: {
  "text-color": "#ffffff"
}

示例

map.addLayer({
  id: "cluster-count",
  type: "symbol",
  source: "grundbuch",
  filter: ["has", "point_count"],
  layout: {
    "text-field": "{point_count_abbreviated}",
    "text-font": ["DIN Offc Pro Medium", "Arial Unicode MS Bold"],
    "text-size": 12
  },
  paint: {
    "text-color": "#ffffff"
  }
});