Skip to content

Commit

Permalink
feat: allow datashader to reload errored tiles
Browse files Browse the repository at this point in the history
  • Loading branch information
maihde committed Apr 14, 2021
1 parent 000b2f7 commit de7ae55
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions x-pack/plugins/maps/public/datashader/datashader_layer.js
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,25 @@ export class DatashaderLayer extends AbstractLayer {
});

mbMap._render();
// mapbox-gl has bugs #10031 and #10494 that ignore the cache control
// headers provided by Datashader; these exist up to at least v2.2.0
// for now, datashader will return an 'error' code of 503
if (!this.cacheCheck) {
this.cacheCheck = setInterval(() => {
const sourceCache = mbMap.style.sourceCaches[sourceId];
for (const id in sourceCache._tiles) {
const tile = sourceCache._tiles[id];
if (tile.state === 'errored' && tile.expirationTime === null) {
// Try any errored tiles again in 5 seconds by setting expiration time
sourceCache._tiles[id].expirationTime = Date.now() + 5;
} else if (tile.state === 'errored' && tile.expirationTime < Date.now()) {
// If an errored tile has expired reload it
sourceCache._tiles[id].expirationTime = Date.now() - 1;
sourceCache._reloadTile(id, 'reloading');
}
}
}, 5000);
}
}

this._setTileLayerProperties(mbMap, mbLayerId);
Expand Down

0 comments on commit de7ae55

Please sign in to comment.