Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OpenLayers: How to refresh map after changing the vector layer

Tags:

openlayers

In OpenLayers, I have a cluster strategy to limit how many features/points the user sees on the map. When the user is fully zoomed in however, I want to turn off the clustering strategy so that all features are shown. To do this I am catching the zoom event like this:

map.events.register("zoomend", this, function (e) {
    if (map.getZoom() === this.mapMaxZoom) {
        // Don't cluster at this level. No matter what.
        this.vector.strategies[0].threshold = 1000;
        console.log("setting the clustering strategy to 1000");
    }
});

This kinda works, but I don't see the new clustering applied - I have to zoom back out again to see the clustering change to a threshold of 1000 (and thus show all features). I need some way to force openlayers to refresh. I've tried calling map.redraw() but that doesn't help. Any ideas?

like image 814
Matt Roberts Avatar asked Apr 27 '12 07:04

Matt Roberts


3 Answers

For openlayers > 3

vectorlayer.getSource().refresh()
like image 62
Argiropoulos Stavros Avatar answered Sep 30 '22 11:09

Argiropoulos Stavros


vectorlayer.refresh({force:true}); Try this.

like image 15
Kliver Max Avatar answered Oct 12 '22 17:10

Kliver Max


You should call redraw() method on layer not map - this.vector.redraw()

like image 6
igorti Avatar answered Oct 12 '22 16:10

igorti