【问题标题】:Openlayers 5.3 How to reload ImageWMS source to show updated data from serverOpenlayers 5.3 如何重新加载 ImageWMS 源以显示来自服务器的更新数据
【发布时间】:2019-02-04 20:17:00
【问题描述】:

我创建了一个 openlayers 地图(版本 5.3)。我添加了一个 ImageLayer,创建了一个 ImageWMS 源来与 ArcGis 服务器对话。图层显示正常。我现在需要每 30 秒刷新一次该层。

我尝试使用刷新方法https://openlayers.org/en/latest/apidoc/module-ol_source_ImageWMS-ImageWMS.html#refresh,但没有运气。我需要的是源重新加载网址。但它根本不这样做。

我尝试在 url 中添加一个带有时间戳的参数,但 ArcGis 根本不喜欢这样。

const wms_source =  new ImageWMS({
        url: 'https://my_secret_domain/arcgis/services/Project/TEST_Lightning/MapServer/WMSServer?request=GetMap',
        projection: 'EPSG:4326',
        styles: 'default',
        params: {
            layers: '0',

        },

    })
    const lightning_layer =  new ImageLayer({


    })
lightning_layer.setSource(wms_source);
this.map = new Map({
        layers: [baseLayer, lightning_layer ],

        target: document.getElementById('lightning'),
        view: new View({

            center: fromLonLat([175.79, -37.79]),
            zoom: 7,
            projection: 'EPSG:3857'
        })
    });
// I would expect this to reload the source ...
// but looking into the debugger shows that it is not.
wms_source.refresh

有谁知道如何重新加载源以显示来自服务器的更新数据?

【问题讨论】:

  • 感谢您的评论 JGH,我试过了 - 但仍然没有改变。如果我更大幅度地更改 URL,例如从 https 到 http - 然后刷新会重新加载图层。但不是在使用时间戳方法时
  • 再次感谢您的评论 JGH,您的评论最终帮助了我。 In 为我指明了正确的方向。

标签: openlayers openlayers-5


【解决方案1】:

感谢 JGH 的评论,我找到了我需要改变的地方。

我没有将 timestemp 添加到源的初始设置中,但我添加了间隔函数,其中我每 30 秒更新一次 URL,然后运行刷新 ...

setInterval(() => {
    wms_source.setUrl('https://my_top_secret_domain/Project/TEST_Lightning/MapServer/WMSServer?request=GetMap&TIMESTAMP=' + new Date().getTime());
        this.wms_source.refresh();
    }, 30000); // 30s

现在按预期工作

【讨论】:

    猜你喜欢
    • 2018-07-08
    • 1970-01-01
    • 1970-01-01
    • 2018-06-01
    • 1970-01-01
    • 2013-12-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多