update bounds whenever files are added

This commit is contained in:
vcoppe
2024-05-07 12:37:21 +02:00
parent 44cc39fbd6
commit f2bba14174

View File

@@ -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);