fix: do not load all datalayers at once (#2402)

Some maps have dozens, even hundreds of layers
This commit is contained in:
David Larlet 2024-12-23 13:36:04 -05:00 committed by GitHub
commit a62bcf6d57
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -581,9 +581,13 @@ export default class Umap extends ServerStored {
this.fire('datalayersloaded') this.fire('datalayersloaded')
const toLoad = [] const toLoad = []
for (const datalayer of this.datalayersIndex) { for (const datalayer of this.datalayersIndex) {
if (datalayer.showAtLoad()) toLoad.push(datalayer.show()) if (datalayer.showAtLoad()) toLoad.push(() => datalayer.show())
} }
await Promise.all(toLoad) while (toLoad.length) {
const chunk = toLoad.splice(0, 10)
await Promise.all(chunk.map((func) => func()))
}
this.dataloaded = true this.dataloaded = true
this.fire('dataloaded') this.fire('dataloaded')
} }