How to Refresh / Reload a KML layer in OpenLayers. Dynamic KML Layer.
Posted
by Ozaki
on Stack Overflow
See other posts from Stack Overflow
or by Ozaki
Published on 2010-06-08T06:40:49Z
Indexed on
2010/06/09
4:42 UTC
Read the original article
Hit count: 222
TLDR See my answer below on how to refresh the layer.
So far I have tried action function as follows:
function RefreshKMLData(layer) {
layer.loaded = false;
layer.setVisibility(true);
layer.redraw({ force: true });
}
set interval of the function:
window.setInterval(RefreshKMLData, 5000, KMLLAYER);
the layer itself:
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
})
})
});
the url for KMLLAYER with Math random so it doesnt cache:
var MYKMLURL = var currentanchorpositionurl = 'http://' + host + '/data?_salt=' + Math.random();
I would have thought that this would Refresh the layer. As by setting its loaded to false unloads it. Visibility to true reloads it and with the Math random shouldn't allow it to cache? So has anyone done this before or know how I can get this to work?
TLDR See my answer below on how to refresh the layer.
© Stack Overflow or respective owner