7

I have a webpage that displays a GeoTIFF served via GeoServer as an OpenLayers3 ImageWMS layer. What I need is to (via a button) reload the OL3 layer after the underlying GeoTIFF changes.

I searched around, and tried

layer.dispatchChangeEvent();

on the layer in question. But the map/image isn't updated.

I have tried

1) removing the layer, constructing a new layer from the GeoTIFF and add it back using JavaScript.

2) disabling caching for the raster layer in GeoServer.

3) using layer.getSource().dispatchChangeEvent(); as suggested by @ahocevar's answer.

None solved the problem.

The only thing that works is to reload the whole webpage, in which case the map shows the new image but all states in the page is lost.

How can I reload the layer without having to reload the whole page?

4 Answers 4

4

A solution I've found is updating the source parameters, like this:

layer.getSource().updateParams({"time": Date.now()});

this triggers a new request to the source server

0
1

When the data on the server changes, it's the source that needs to reload, not the layer. So you'll need to call

wmsLayer.getSource().dispatchChangeEvent();

in v3.0.0, or

wmsLayer.getSource().changed();

in later versions.

1
  • 1
    Thanks a lot for the answer. Do you have a reference for this in the documentation? I tried layer.getSource().changed() (in OL3), and got TypeError: layer.getSource(...).changed is not a function. Any pointers?
    – tinlyx
    Commented Dec 12, 2014 at 18:21
1

Try refreshing the map :

map.updateSize();

Does the trick for me.

1
  • This seems to trigger the rendering, but not include an redownload
    – Mapper
    Commented Oct 18, 2015 at 17:31
0

Too little too late. But for others you can check out documentation on link below:

http://openlayers.org/en/v4.6.4/apidoc/ol.source.Source.html#changed

layer.getSource().changed(); // that works for me
3
  • 1
    Please copy the gist of the answer into your own, in case the link dies later. Commented Dec 9, 2017 at 22:55
  • 1
    The link is dead Jim...!
    – Michael
    Commented Jul 27, 2018 at 14:12
  • Fixed the link to the documentation
    – Dan
    Commented Aug 14, 2018 at 19:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.