Skip to content

Commit 309a5b8

Browse files
committed
fix: Fit bounds on map show
1 parent f94f4a8 commit 309a5b8

File tree

1 file changed

+6
-20
lines changed

1 file changed

+6
-20
lines changed

src/components/ItemResults/MapView.tsx

Lines changed: 6 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -47,31 +47,17 @@ function MapView({ id, hidden, results, highlightItem, setHighlightItem }: MapVi
4747
};
4848
}, [results]);
4949

50-
51-
// Fit the map view around the current results bbox
5250
useEffect(() => {
53-
const bounds = results?.features.length && getBbox(results);
54-
55-
map?.once("load", () => {
56-
// For some reason this is need to set the bounds after the initial load
51+
if (map && !hidden) {
5752
map.resize();
58-
if(bounds) {
53+
54+
const bounds = results?.features.length && getBbox(results);
55+
if (bounds) {
5956
const [x1, y1, x2, y2] = bounds;
60-
map.fitBounds([x1, y1, x2, y2], { padding: 30, duration: 10 });
57+
map.fitBounds([x1, y1, x2, y2], { padding: 30 });
6158
}
62-
});
63-
64-
if (map && bounds) {
65-
const [x1, y1, x2, y2] = bounds;
66-
map.fitBounds([x1, y1, x2, y2], { padding: 30 });
67-
}
68-
}, [map, results]);
69-
70-
useEffect(() => {
71-
if (map && !hidden) {
72-
map.resize();
7359
}
74-
}, [hidden, map]);
60+
}, [hidden, map, results]);
7561

7662

7763
const handleHover = useCallback((e: MapLayerMouseEvent) => {

0 commit comments

Comments
 (0)