Hello!
I’ve write a code that sets this function to a WMS source. Could you check that this code resolves the issue? If it works, I would create a GitHub issue to provide the ability to add and configure this function from Maps.
@Subscribe
public void onReady(ReadyEvent event) {
map.getElement().executeJs("""
setTimeout(() => {
const layers = this.olMap.getLayers().getArray();
for (const layer of layers) {
if (layer.constructor.name !== 'TileLayer' || !layer.getSource()) {
continue;
}
const source = layer.getSource();
if (source.constructor.name !== 'TileWMS') {
continue;
}
const retryCodes = [408, 429, 500, 502, 503, 504];
const retries = {};
source.setTileLoadFunction((tile, src) => {
const image = tile.getImage();
fetch(src)
.then((response) => {
if (retryCodes.includes(response.status)) {
retries[src] = (retries[src] || 0) + 1;
if (retries[src] <= 3) {
setTimeout(() => tile.load(), retries[src] * 1000);
}
return Promise.reject();
}
return response.blob();
})
.then((blob) => {
const imageUrl = URL.createObjectURL(blob);
image.src = imageUrl;
setTimeout(() => URL.revokeObjectURL(imageUrl), 5000);
})
.catch(() => tile.setState(3)); // error
});
}
} , 0);
""");
}