简体   繁体   English

OpenLayers刷新战略问题

[英]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). 我正在开发一个应用程序,其中一部分使用OpenLayers(调用Geoserver服务的WMS)显示一些经常更新的数据(船只轨道 - 或更具体地说,一系列点)。

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. 我希望这个船只轨道在设定的时间间隔内更新 - OpenLayers.Strategy.Refresh似乎是最适合的方式。 I modified the wms.html example (OpenLayers 2.11) slightly to try this, ie: 我稍微修改了wms.html示例(OpenLayers 2.11)来尝试这个,即:

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. 据我所知,这应该按原样工作(即每隔6秒刷新一次进行中的层),但没有任何反应。 The underlying WMS is getting updated - if I refresh the map manually, the updated data will appear. 底层WMS正在更新 - 如果我手动刷新地图,将显示更新的数据。

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. 我在Firebug中没有任何错误或其他任何错误,它只是没有做任何事情。

Well, it turns out that you can't do a refresh strategy on a WMS service, as far as I can tell. 好吧,事实证明,就我所知,你无法对WMS服务进行刷新策略。 So I converted my code to use WFS instead, and it works as expected. 所以我将我的代码转换为使用WFS,它按预期工作。 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. 请注意,我还需要一个BBOX策略。 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. 我发现的另一个问题是我需要手动指定geometryName,否则它将默认为“the_geom”,这对于我的图层不存在。

I'm pretty sure you need to add a new OpenLayers.Strategy.Static() strategy for it to work. 我很确定你需要添加一个new OpenLayers.Strategy.Static()策略才能工作。 And you need to activate your Refresh strategy which means you have to stick it in a separate variable. 并且您需要激活Refresh策略,这意味着您必须将其添加到单独的变量中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM