Openlayers-3 Force a map refresh
Asked Answered
L

6

15

I have a custom styling that shows/hides features on the map, but when it is applied it doesn't activate until the map refreshes due to a feature update, but I need it to trigger immediately.

I tried map.render and renderSync() but they did nothing. mapResize() doesn't appear to do anything either, but if I wait for a feature to be updated or move the map it works.

Any ideas? How can I FORCE the map to redraw on demand, regardless of a feature update?

Limes answered 23/6, 2015 at 8:28 Comment(1)
You can refresh your map using the methods from the answer below: #25995834Passageway
B
19

I believe you need to force your layer's source to update, you can do so by calling the changed function on it:

yourLayer.getSource().changed();

see: http://openlayers.org/en/v3.6.0/apidoc/ol.source.Source.html

Baboon answered 23/6, 2015 at 13:52 Comment(1)
Turns out I WAS doing this at another point in my codebase - must have forgotten or someone else used it! Thanks.Limes
R
7

I've finally found a solution to refresh a layer on openlayers 3.

You have to update params of the layer source like this:

var source = yourLayer.getSource();
var params = source.getParams();
params.t = new Date().getMilliseconds();
source.updateParams(params);
Role answered 19/10, 2015 at 10:9 Comment(0)
Z
7

To solve the issue just use

this.map.updateSize();
Zoography answered 11/9, 2019 at 10:21 Comment(1)
a handy jquery snippet: $(window).resize(function(){if(map){map.updateSize();}});Leviathan
T
3

In case Sarumanatee doesn't work for you, you can try this one:

map.render();

I am using ol3.

Thiol answered 23/2, 2017 at 11:4 Comment(0)
P
0

one way is to group your features based on their purpose and put each group on different layers, then you can easily show or hide specified layer that have the features your want to hide or show.

Pasty answered 26/6, 2015 at 0:38 Comment(1)
I was under the impression that using many layers impacted performance - have you found this?Limes
J
0

Use yourlayer.source().updateParams({CQL_FILTER:"1=1"});

It will definitely work.

Jewess answered 20/4, 2018 at 13:42 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.