Refresh / Redraw a Layer in OpenLayers (KML) Network-Link Auto Refresh
- by Ozaki
TLDR I want to refresh a layer on a timer so it plots the new kml data (like update-link / network link)
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?