fix: do not load all datalayers at once

Some maps have dozens, even hundreds of layers

Co-authored-by: David Larlet <david@larlet.fr>
This commit is contained in:
Yohan Boniface 2024-12-23 19:16:09 +01:00
parent 49d1dbf36e
commit f7b4cb252d

View file

@ -581,9 +581,13 @@ export default class Umap extends ServerStored {
this.fire('datalayersloaded')
const toLoad = []
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.fire('dataloaded')
}