0

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.

6
  • Why do you need to refresh the tiles?
    – Chase Choi
    Sep 19, 2017 at 0:30
  • There is a data source which updating intervally each 5 seconds, so I need map vector tiles update according to data source changes. Sep 19, 2017 at 4:19
  • Try map.updateSize() to see if does the job.
    – pavlos
    Sep 19, 2017 at 7:18
  • @pavlos Unfortunately it doesn't work! Only if I change the zoom level it will works! But I don't want do it by changing the zoom level. Sep 19, 2017 at 9:14
  • did you try updateParams? Sep 21, 2017 at 15:11

2 Answers 2

1

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();
}
0

I am setting myself a little helper function to reload a layer.

Expiring and clearing the tile cache does not seem to have any effect on the procedure. I do however need to redraw the layer. Just updating the source will not automatically trigger a layer redraw.

  layer.reload = () => {

    //source.tileCache.expireCache();
    //source.tileCache.clear();

    source.clear();
    source.refresh({force: true});

    layer.redraw();

  };

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.