mapboxgl实时修改图标透明度

1.加载图层时,图标透明度设置为1.0

paint: {
            'icon-opacity':1.0,
            'text-color': 'rgba(255, 255, 255, 0.97)'
          }

2.闪烁某个要素图标

var time1 = setTimeout(function(){
        that.map.setPaintProperty('layerid', 'icon-opacity',
        ['case', ['match', ['get', 'id'], id, true, false], 0.5, 1]);
      },500)
      var time2 = setTimeout(function(){
        that.map.setPaintProperty('layerid', 'icon-opacity',1);
      },1000)
      var time3 = setTimeout(function(){
        that.map.setPaintProperty('layerid', 'icon-opacity',
        ['case', ['match', ['get', 'id'], id, true, false], 0.5, 1]);
      },1500)
      var time4 = setTimeout(function(){
        that.map.setPaintProperty('layerid', 'icon-opacity',1);
      },2000)

3.清除定时器

clearTimeout(this.time1)

效果图


闪烁.gif
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容