[OpenLayers-Users] refresh data in layer only when visible

tvnc tvnc1979 at gmail.com
Wed Nov 30 11:38:46 EST 2011


hi,
i have limited bandwidth link so i do not want to load data from my mysql 
database while layer is deselected in layerswitcher menu.

Here is my code

var source = 'test.php?' + Math.random();

var saga = new OpenLayers.Layer.Vector('<img src="./img/plavi.png" width="12" 
height="12"/> Objekti - AIS MMPiV', {
            	 styleMap: aisMMPiVstil,     
                projection: map.displayProjection,
                strategies: [new OpenLayers.Strategy.Fixed()],             
                protocol: new OpenLayers.Protocol.HTTP({
                        url: source,
                        format: new OpenLayers.Format.Text({
                        extractStyles: false,
                        extractAttributes: true
                    })
                })
            });
			 
             window.setInterval(UpdateKmlLayer, 20000, saga); 

function UpdateKmlLayer(layer) {
               
                layer.loaded = false;
                layer.refresh({ force: true, params: { 'key': Math.random()} });
}

I tried with next code but with no luck

function UpdateKmlLayer(layer) {
              
                if(layer.visibility==true){
                layer.loaded = false;
                layer.refresh({ force: true, params: { 'key': Math.random()} });
}
}

how to solve this problem



More information about the Users mailing list