How to force a ol.source.Vector to reload data from server?

I had the same requirement, loading a subset of data when zoomed out and loading more of that data when zoomed in. I solved it with help from this question: reload ServerVector with different zoom levels in openlaers3

First replace your vectorSource strategy strategy: ol.loadingstrategy.bbox with a custom loading strategy:

strategy: function(extent, resolution) {
    if(this.resolution && this.resolution != resolution){
        this.loadedExtentsRtree_.clear();
    }
    return [extent];
}

Second, at the beginning of your vectorSource loader function, add the following line:

this.resolution = resolution

Now when the resolution/zoom level changes, the loaded extents stored in the vectorSource will be cleared. You could make this a bit more intelligent by only removing the most recent extent for example, but this works well for me.

Tags:

Openlayers