1

I would like to load specific leaflet tiles, based on changes to the user's activity. So, say, a user opens the map and sees particular tiles. Then, after a few minutes, some tiles are reloaded (because they have changed) and displayed. Perhaps the original was orange, the new one is blue.

This question and answer give a suggestion that could work for refreshing all the tiles, but that would be rather inefficient.

Is there a way to force the reload of specific individual tiles?

2 Answers 2

2

You'll have to implement a plugin for that, subclassing L.TileLayer and overwriting its createTile() method, so that you either have references to the tiles, or adding some kind of timeout or logic to each (loading/loaded) tile.

There's no generic way of doing this as of now, you'll have to code it.

1
  • Thanks. I'll look into this.
    – MastaBaba
    Commented May 29, 2016 at 18:07
1

I know I'm way to late, but I have a solution to this. You can manipulate the url using a parameter that you update only for the tiles that should reload. The rest will keep the cached tile image.

L.TileLayer.CustomLayer = L.TileLayer.extend({
    getTileUrl: (coords) => {
        var test = some_function_deciding_test_based_on_tile(coords);
        return `http://example.com/tile_${coords.x}_${coords.y}.png?test=${test}`;
    }
});

In this case if some_function_deciding_test_based_on_tile(coords) returns the same value as it did the previous time, the cached tile will be used. Otherwise a new tile will be fetched.

1
  • Clever and simple.
    – MastaBaba
    Commented Dec 2, 2019 at 18:12

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