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.

My question is

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

Thanks

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

  • 1
    This does not really answer the question. If you have a different question, you can ask it by clicking Ask Question. You can also add a bounty to draw more attention to this question. – Evil Genius Sep 28 '15 at 14:29
  • you're right, I wanted to add a comment instead of an answer... – giohappy Sep 28 '15 at 14:39
  • 1
    I've edited my answer, with an actual answer :) – giohappy Sep 28 '15 at 16:07
1

Have you tried refreshing the map :

map.updateSize();

Does the trick for me

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

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

We're looking for long answers that provide some explanation and context. Don't just give a one-line answer; explain why your answer is right, ideally with citations. Answers that don't include explanations may be removed.

  • Please copy the gist of the answer into your own, in case the link dies later. – lynxlynxlynx Dec 9 '17 at 22:55
  • The link is dead Jim...! – Michael Jul 27 '18 at 14:12
  • Fixed the link to the documentation – Dan Aug 14 '18 at 19:29
0

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
    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 Dec 12 '14 at 18:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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