TLDR我想在计时器上刷新一个图层,以便绘制新的 kml 数据(如更新链接/网络链接)
到目前为止,我已经尝试了如下操作功能:
function RefreshKMLData(layer) {
layer.loaded = false;
layer.setVisibility(true);
layer.redraw({ force: true });
}
设置函数的间隔:
window.setInterval(RefreshKMLData, 5000, KMLLAYER);
图层本身:
var KMLLAYER = new OpenLayers.Layer.Vector("MYKMLLAYER", {
projection: new OpenLayers.Projection("EPSG:4326"),
strategies: [new OpenLayers.Strategy.Fixed()],
protocol: new OpenLayers.Protocol.HTTP({
url: MYKMLURL,
format: new OpenLayers.Format.KML({
extractStyles: true,
extractAttributes: true
})
})
});
带有数学随机的 KMLLAYER 的 url,因此它不会缓存:
var MYKMLURL = var currentanchorpositionurl = 'http://' + host + '/data?_salt=' + Math.random();
我原以为这会刷新图层。通过将其加载为 false 卸载它。对 true 的可见性重新加载它并且使用 Math random 不应该允许它缓存?那么有没有人这样做过或者知道我怎样才能让它工作?