Openlayers-3 Force a map refresh

user4773894 picture user4773894 · Jun 23, 2015 · Viewed 22.1k times · Source

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?

Answer

Sarumanatee picture Sarumanatee · Jun 23, 2015

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