Problems updating OpenLayers

I am developing an application, part of which uses OpenLayers (calling the WMS service maintained by Geoserver), displaying some frequently updated data (the track of the ship, or, more specifically, a number of points).

I would like this ship track to be updated at a given interval - OpenLayers.Strategy.Refresh seems to be the most appropriate way to do this. I slightly modified the wms.html example (OpenLayers 2.11) to try this, for example:

underway = new OpenLayers.Layer.WMS("Underway Data", "http://ubuntu-geospatial-server:8080/geoserver/underway/wms", {'layers': 'underway:ss2011_v03', transparent: true, format: 'image/gif'}, {isBaseLayer: false}, {strategies : [new OpenLayers.Strategy.Refresh({interval: 6000})]} ); map.addLayers([layer, underway]); 

From what I can say, this should work as it is (i.e. update the current layer every 6 seconds), but nothing happens. Updated basic WMS is updated - if I update the map manually, updated data will appear.

I am sure that I am missing something fairly obvious, any help would be greatly appreciated. I don't get any errors in Firebug or anything else, it just does nothing.

+7
source share
2 answers

Well, it turns out that you cannot make an upgrade strategy in WMS, as far as I can tell. So I converted my code to use WFS instead, and it works as expected. The code:

  underway = new OpenLayers.Layer.Vector("WFS", { strategies: [new OpenLayers.Strategy.BBOX(), new OpenLayers.Strategy.Refresh({interval: 4000, force: true})], protocol: new OpenLayers.Protocol.WFS({ url: "http://ubuntu-geospatial-server:8080/geoserver/wfs", featureType: "ss2011_v03", featureNS: "http://csiro.au/underway", geometryName: "position" }); 

Please note that I also need a BBOX strategy. Another problem I found was that I needed to manually specify the name geometryName, otherwise the default would be "the_geom", which does not exist for my layer.

+10
source

I am sure you need to add the new OpenLayers.Strategy.Static() strategy to make it work. And you need to activate the Refresh strategy, which means you have to embed it in a separate variable.

-2
source

All Articles