简体   繁体   English

传单删除层在使用 javascript 的 Internet Explorer 11 中不起作用

[英]leaflet remove layer is not working in internet explorer 11 using javascript

I use below script to update my image dynamically, its working fine in chrome and Edge but in internet explorer new image get added unable to remove old image, no error in console.我使用下面的脚本动态更新我的图像,它在 chrome 和 Edge 中工作正常,但在 Internet Explorer 中添加新图像无法删除旧图像,控制台中没有错误。

In below script its passing this condition if(oldhandle != null && map.hasLayer(oldhandle ))在下面的脚本中,它传递了这个条件if(oldhandle != null && map.hasLayer(oldhandle ))

var layerHandle;
var map;

function updateLayer(){
    var bounds=XXX;
    var imageUrl=XXX;
    var oldhandle = layerHandle;         
    layerHandle = L.imageOverlay(imageUrl, bounds).on("load",function(){
                    if(oldhandle != null  && map.hasLayer(oldhandle ))
                        map.removeLayer(oldhandle);
                    });
        
    layerHandle.addTo(map);
}

I have the same problem, however I resolved my issue like this:我有同样的问题,但是我解决了这样的问题:

var map;

function updateLayer(){
    var bounds=XXX;
    var imageUrl=XXX;
    var imageName="myImage";     
    layerHandle = L.imageOverlay(imageUrl, bounds, {className:imageName}).on("load",function(){
                  
                    });
        removeMyLayer(imageName);
    layerHandle.addTo(map);
}

function removeMyLayer(imageName){
     map.eachLayers(function(layer){
      if(layer.options && layer.options.className==imageName){
        map.removeLayer(layer);
     }
   })
}

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

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