fix bounds for waypoints

This commit is contained in:
vcoppe committed 2026-10-08 08:15:22 +02:00
1 parent 63ba8596a7
commit b29c4cdb08
1 file changed
+33 -8
+33 -8
View File
@@ -93,15 +93,41 @@ export class BoundsManager {
} }
centerMapOnSelection() { centerMapOnSelection() {
let stats = get(statistics); const bounds = new maplibregl.LngLatBounds([180, 90, -180, -90]);
const stats = get(statistics);
if (stats.global.bounds) { if (stats.global.bounds) {
// TODO take waypoints into account bounds.extend([
let bounds = new maplibregl.LngLatBounds([ [stats.global.bounds.west, stats.global.bounds.south],
stats.global.bounds.west, [stats.global.bounds.east, stats.global.bounds.north],
stats.global.bounds.south,
stats.global.bounds.east,
stats.global.bounds.north,
]); ]);
}
// the waypoints are not part of the statistics of the selection
const selection = get(engine.selection);
let waypointIds: Set<string> | undefined; // all the waypoints of the file if undefined
let fileIds: string[] = [];
switch (selection.type) {
case 'file':
fileIds = selection.fileIds;
break;
case 'waypoints':
fileIds = [selection.fileId];
break;
case 'waypoint':
fileIds = [selection.fileId];
waypointIds = new Set(selection.waypointIds);
break;
}
const files = get(engine.files);
for (const fileId of fileIds) {
const file = files.get(fileId);
if (!file) continue;
for (const feature of get(file).waypoints.features) {
if (waypointIds && !waypointIds.has(feature.properties.waypointId)) continue;
bounds.extend(feature.geometry.coordinates as [number, number]);
}
}
if (!this.validBounds(bounds)) return; if (!this.validBounds(bounds)) return;
get(map)?.fitBounds(bounds, { get(map)?.fitBounds(bounds, {
padding: 80, padding: 80,
@@ -109,7 +135,6 @@ export class BoundsManager {
maxZoom: 15, maxZoom: 15,
}); });
} }
}
validBounds(bounds: maplibregl.LngLatBounds) { validBounds(bounds: maplibregl.LngLatBounds) {
return ( return (