Wednesday, 4 February 2015

openlayers 4: force refresh tiles in ol.source.VectorTile on interval



I'm using openlayers 4, and have a ol.source.VectorTile which uses MVT tiles. I want to refresh the tiles every 5 seconds without refreshing the browser. I've used source.changed(), source.refresh(), layer.changed() and map.renderSync()


But none of them not working for me, I mean tiles not refreshed after calling any of them.


Can anyone help me please.



Answer



I finally found a solution to force ol.source.VectorTile layer to refresh tiles. This is the first step to create my vector tile layer:


var layer = ol.layer.VectorTile({
preload: 0,
source: new ol.source.VectorTile({
cacheSize: 1,
format: new ol.format.MVT({

featureClass: ol.Feature
}),
})
});

And layer in my refresh function do this:


function refresh() {
var source = layer.getSource();
source.tileCache.expireCache({});
source.tileCache.clear();

source.refresh();
}

No comments:

Post a Comment