From f7b4cb252dd362948f6313a84eb5e38069b49607 Mon Sep 17 00:00:00 2001 From: Yohan Boniface Date: Mon, 23 Dec 2024 19:16:09 +0100 Subject: [PATCH] fix: do not load all datalayers at once Some maps have dozens, even hundreds of layers Co-authored-by: David Larlet --- umap/static/umap/js/modules/umap.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/umap/static/umap/js/modules/umap.js b/umap/static/umap/js/modules/umap.js index 84daa7f15..42aaeb982 100644 --- a/umap/static/umap/js/modules/umap.js +++ b/umap/static/umap/js/modules/umap.js @@ -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') }