forked from MapComplete/MapComplete
UX: make loading of background layers a bit more stable and faster
This commit is contained in:
parent
e0dcd1cc1e
commit
27b9940eb5
1 changed files with 12 additions and 1 deletions
|
@ -551,7 +551,7 @@ export class MapLibreAdaptor implements MapProperties, ExportableMap {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private async setBackground(): Promise<void> {
|
private async setBackground(retryAttempts: number = 3): Promise<void> {
|
||||||
const map = this._maplibreMap.data
|
const map = this._maplibreMap.data
|
||||||
if (!map) {
|
if (!map) {
|
||||||
return
|
return
|
||||||
|
@ -585,12 +585,23 @@ export class MapLibreAdaptor implements MapProperties, ExportableMap {
|
||||||
} else {
|
} else {
|
||||||
// Make sure that the default maptiler style is loaded as it gives an overlay with roads
|
// Make sure that the default maptiler style is loaded as it gives an overlay with roads
|
||||||
const maptiler = AvailableRasterLayers.maptilerDefaultLayer.properties
|
const maptiler = AvailableRasterLayers.maptilerDefaultLayer.properties
|
||||||
|
try {
|
||||||
|
|
||||||
|
await this.awaitStyleIsLoaded()
|
||||||
if (!map.getSource(maptiler.id)) {
|
if (!map.getSource(maptiler.id)) {
|
||||||
this.removeCurrentLayer(map)
|
this.removeCurrentLayer(map)
|
||||||
map.addSource(maptiler.id, MapLibreAdaptor.prepareWmsSource(maptiler))
|
map.addSource(maptiler.id, MapLibreAdaptor.prepareWmsSource(maptiler))
|
||||||
map.setStyle(maptiler.url)
|
map.setStyle(maptiler.url)
|
||||||
await this.awaitStyleIsLoaded()
|
await this.awaitStyleIsLoaded()
|
||||||
}
|
}
|
||||||
|
}catch (e) {
|
||||||
|
if(retryAttempts > 0){
|
||||||
|
window.requestAnimationFrame(() => {
|
||||||
|
console.log("Retrying to set the background ("+retryAttempts+" attempts remaining)... Failed because",e)
|
||||||
|
this.setBackground(retryAttempts-1)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!map.getLayer(addLayerBeforeId)) {
|
if (!map.getLayer(addLayerBeforeId)) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue