fix: resize map before fitBounds and defer with rAF to avoid layout-timing glitch
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user