From f2bba14174145d1a050833c9c772fd61c2da226c Mon Sep 17 00:00:00 2001 From: vcoppe Date: Tue, 7 May 2024 12:37:21 +0200 Subject: [PATCH] update bounds whenever files are added --- website/src/lib/stores.ts | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/website/src/lib/stores.ts b/website/src/lib/stores.ts index 1df67982..8fedf07a 100644 --- a/website/src/lib/stores.ts +++ b/website/src/lib/stores.ts @@ -45,6 +45,16 @@ function updateGPXData() { } fileObservers.subscribe((files) => { // Maintain up-to-date statistics + if (files.size > fileStatistics.size) { // Files are added + let bounds = new mapboxgl.LngLatBounds([180, 90, -180, -90]); + let mapBounds = new mapboxgl.LngLatBounds([180, 90, -180, -90]); + if (fileStatistics.size > 0) { // Some files are already loaded + mapBounds = get(map)?.getBounds() ?? mapBounds; + bounds.extend(mapBounds); + } + targetMapBounds.set(bounds); + } + fileStatistics.forEach((stats, fileId) => { if (!files.has(fileId)) { fileStatistics.delete(fileId); @@ -150,14 +160,6 @@ export async function loadFiles(list: FileList) { } } - let bounds = new mapboxgl.LngLatBounds([180, 90, -180, -90]); - let mapBounds = new mapboxgl.LngLatBounds([180, 90, -180, -90]); - if (get(fileObservers).size > 0) { - mapBounds = get(map)?.getBounds() ?? mapBounds; - bounds.extend(mapBounds); - } - targetMapBounds.set(bounds); - dbUtils.addMultiple(files); selectFileWhenLoaded(files[0]._data.id);