开发者

OpenLayers Refresh Strategy Problems

开发者 https://www.devze.com 2023-04-10 09:21 出处:网络
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'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:

开发者_如何学Gounderway = 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.


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.


I'm pretty sure you need to add a new OpenLayers.Strategy.Static() strategy for it to work. And you need to activate your Refresh strategy which means you have to stick it in a separate variable.

0

精彩评论

暂无评论...
验证码 换一张
取 消