Refresh / Redraw a Layer in OpenLayers (KML) Network-Link Auto Refresh

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/08 6:42 UTC
Read the original article Hit count: 1126

Filed under:
|
|
|

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?

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about update