2011-10-03 301 views
7

我正在開發一個應用程序,其中的一部分使用OpenLayers(調用Geoserver服務的WMS)顯示一些頻繁更新的數據(船軌跡 - 或更具體地說,一系列點)。OpenLayers刷新策略問題

我想以設定的時間間隔更新此容器跟蹤 - OpenLayers.Strategy.Refresh看起來像是最適合的方法。我修改了wms.html例(2.11的OpenLayers)小試這一點,即:

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]); 

從我可以告訴,這應該原樣(即刷新每6秒進行層),然而沒有什麼發生。底層的WMS正在更新 - 如果我手動刷新地圖,則會顯示更新的數據。

我敢肯定我錯過了相當明顯的事情,任何幫助將不勝感激。我沒有在Firebug或任何其他方面發生任何錯誤,它只是沒有做任何事情。

回答

10

嗯,事實證明,你不能對WMS服務進行刷新策略,據我所知。所以我將我的代碼轉換爲使用WFS,並按預期工作。代碼:

 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" 
      }); 

請注意,我還需要一個BBOX策略。我發現的另一個問題是,我需要手動指定geometryName,否則它將默認爲「the_geom」,這對我的圖層不存在。

-2

我很確定你需要添加一個new OpenLayers.Strategy.Static()策略才能工作。 而且你需要激活你的Refresh策略,這意味着你必須把它放在一個單獨的變量中。

+0

那裏沒有快樂。我無法在trunk或2.11中找到OpenLayers.Strategy.Static()。我嘗試設置一些看起來可能會工作的策略(bbox,固定),但沒有好處。我的修改後的代碼如下所示: 'bboxStrategy = new OpenLayers.Strategy.BBOX();bboxStrategy.setLayer(underway); bboxStrategy.activate(); refreshStrategy = new OpenLayers.Strategy.Refresh({interval:2000,force:true}); (正在進行);刷新狀態.setLayer(正在進行); refreshStrategy.activate();' 但這導致了同樣的問題,沒有發生。 – Caligari