Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OpenLayers Refresh Strategy Problems

I'm developing an application, part of which uses OpenLayers (calling a Geoserver-served WMS) displaying some frequently updated data (a vessel track - or more specifically, a series of points).

I would like to have this vessel track updated at a set interval - OpenLayers.Strategy.Refresh seems like the most approparite way to do this. I modified the wms.html example (OpenLayers 2.11) slightly to try this, ie:

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 tell, this should work as-is (ie refresh the underway layer every 6 seconds), however nothing happens. The underlying WMS is getting updated - if I refresh the map manually, the updated data will appear.

I'm sure I'm missing something fairly obvious, any help would be much appreciated. I'm not getting any errors in Firebug or anything, it's just not doing anything.

like image 319
Caligari Avatar asked Oct 03 '11 05:10

Caligari


1 Answers

Well, it turns out that you can't do a refresh strategy on a WMS service, 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"
            });

Note that I also need a BBOX strategy. Another gotcha that I found was that I needed to manually specify the geometryName, otherwise it would default to "the_geom", which doesn't exist for my layer.

like image 107
Caligari Avatar answered Sep 25 '22 15:09

Caligari