fix: resize map before fitBounds and defer with rAF to avoid layout-timing glitch

This commit is contained in:
Davide Scaini
2026-04-10 17:44:52 +02:00
parent a20df6bd57
commit 61349e6292
+8 -3
View File
@@ -72,12 +72,17 @@
});
});
// Fit to bbox when detail JSON loads (bbox is null at map init)
// Fit to bbox when detail JSON loads (bbox is null at map init).
// Always resize first so MapLibre knows the real container dimensions,
// and defer with rAF so the browser has finished laying out the container.
$: if (map && bbox) {
const fit = () => map.fitBounds(
const fit = () => requestAnimationFrame(() => {
map.resize();
map.fitBounds(
[[bbox![0], bbox![1]], [bbox![2], bbox![3]]],
{ padding: 40, animate: true },
{ padding: 40, animate: false },
);
});
map.loaded() ? fit() : map.once('load', fit);
}