Skip to content

Commit c2a0241

Browse files
committed
fix: replace offset prop with openPopup in FitBounds component for improved functionality
1 parent 20a7110 commit c2a0241

File tree

2 files changed

+9
-7
lines changed

2 files changed

+9
-7
lines changed

src/Features/Bounds/FitsBounds.tsx

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ interface FitBoundsProps {
1414
disableAnimation?: boolean;
1515
fitBounds?: boolean;
1616
animationKey?: unknown;
17-
offset?: [number, number];
17+
openPopup?: boolean;
1818
}
1919

2020
const serializeKey = (key: unknown): string => {
@@ -57,10 +57,10 @@ const FitBounds = ({
5757
features,
5858
padding = 50,
5959
duration = 1000,
60-
disableAnimation = false,
60+
disableAnimation,
6161
fitBounds = true,
6262
animationKey,
63-
offset = [0, 0],
63+
openPopup,
6464
}: FitBoundsProps) => {
6565
const { current: map } = useMap();
6666
const previousKey = useRef<string>("");
@@ -79,6 +79,10 @@ const FitBounds = ({
7979
}, [validMarkers, featureCoords]);
8080

8181
useEffect(() => {
82+
if (openPopup) {
83+
return;
84+
}
85+
8286
if (!(map && fitBounds && bounds)) {
8387
return;
8488
}
@@ -100,18 +104,16 @@ const FitBounds = ({
100104
map.flyTo({
101105
center: [m.lng, m.lat],
102106
duration: disableAnimation ? 0 : duration,
103-
offset,
104107
zoom: 14,
105108
});
106109
return;
107110
}
108111

109112
map.fitBounds([bounds.getSouthWest().toArray(), bounds.getNorthEast().toArray()], {
110113
duration: disableAnimation ? 0 : duration,
111-
offset,
112114
padding,
113115
});
114-
}, [map, bounds, padding, duration, disableAnimation, animationKey, fitBounds, validMarkers, featureCoords, offset]);
116+
}, [map, bounds, padding, duration, disableAnimation, animationKey, fitBounds, validMarkers, featureCoords, openPopup]);
115117

116118
return null;
117119
};

src/Features/MarkerMap/MarkerMap.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ const MarkerMap = ({
168168
padding={fitBoundsPadding}
169169
duration={disableAnimation ? 0 : fitBoundDuration}
170170
animationKey={fitBoundsAnimationKey}
171-
offset={selectedMarker ? [0, 80] : [0, 0]}
171+
openPopup={!!openPopup}
172172
/>
173173
)}
174174
</MapboxMap>

0 commit comments

Comments
 (0)