我正在寻找解决方案,如何在 leaflet.js 中重新加载图 block ,该图 block 由于错误 503 而未加载。 谢谢
最佳答案
查看 API,我将这段代码放在一起,这应该可以帮助您解决问题:
function reloadImg() { // reload image by changing its src
var src = $(this).attr("src");
var i = src.lastIndexOf('?');
if(i > 0) { // remove previous cache string
src = src.substring(0, i);
}
$(this).attr("src", src + "?nocache=" + (Math.random() * 1000));
}
map.on('layeradd', function(ILayer) { // on adding a new tile
if($.isFunction(ILayer.layer.getContainer)) { // get the container holding the images
$("img", ILayer.layer.getContainer()).error(reloadImg); // apply error handling event
}
});
关于javascript - 如何重新加载 leaflet.js 中未加载的图 block ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30307522/