最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - OpenLayers Refresh Strategy Problems - Stack Overflow

programmeradmin2浏览0评论

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.

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.

Share Improve this question asked Oct 3, 2011 at 5:34 CaligariCaligari 1,4312 gold badges11 silver badges14 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 10

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)

  1. 暂无评论