简体   繁体   English

Mapbox GL 设置符号层的不透明度

[英]Mapbox GL set opacity of symbol layer

I have a symbol layer displaying text on a mapbox map and I am looking for a way to change the opacity of the text.我有一个符号图层在地图框地图上显示文本,我正在寻找一种更改文本不透明度的方法。

this.map.addLayer({
        "id": "symbols",
        "type": "symbol",
        "source": "source_circleCurrentGpsCircle",
        "layout": {
          "text-font": ["Open Sans Regular"],
          "text-field": '{title}',
          "text-size": {
            stops: [
              [0, 0],
              [22, metersToPixelsAtMaxZoom * 2]
            ],
            base: 2
          }
        },
        "paint": {
          "text-color": "#00FF00"
        }
      });

I tried a few things like the following我尝试了一些类似以下的事情

this.map.setPaintProperty('symbols', 'symbol-opacity', .6);

I think I just need the correct property name.我想我只需要正确的属性名称。 Is it possible to set a class for the symbol?是否可以为符号设置类? I could adjust the opacity easily that way.我可以通过这种方式轻松调整不透明度。

I figured it out.我想到了。 It turns out to be the text-opacity property, not symbol-opacity.结果是文本不透明度属性,而不是符号不透明度。 Seems obvious now.现在似乎很明显。

To change the opacity on a label from a symbol type layer use the text-opacity property.要从符号类型图层更改标签上的不透明度,请使用text-opacity属性。 Here's the documentation. 这是文档。

Example:例子:

this.map.setPaintProperty('layer_name', 'text-opacity', .6);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM