mapbox中removeSource出错


添加了一个清除图层的按钮

    const clearMarker = () => {
      const map: any = props.map;
      map.removeLayer('markerLyr');
      map.removeSource("marker");
    }

但是点击按钮,总是报错,先记录一下,显示The layer 'markerLyr' does not exist in the map's style and cannot be removed.There is no source with this ID
注释掉函数内容,console.log某个值,发现函数执行了两遍,暂不知原因。

在vue中将@click改为@click.once解决,这样有一个弊端,就是事件只执行一次就不再执行了,

另一种方式,做一个定时器

      setTimeout(() => {
        map.removeLayer('markerLyr');
        map.removeSource("markerSrc");
      }, 500);


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM