mapboxgl实时修改图标透明度

2021-11-04  本文已影响0人  SarahLee1122

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
上一篇 下一篇

猜你喜欢

热点阅读