【发布时间】: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 为我指明了正确的方向。