Skip to content

Commit

Permalink
Merge branch 'DBC22-1616' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
fatbird committed Jan 30, 2024
2 parents 6fe0a40 + 56ad177 commit c1d6f43
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions src/frontend/src/Components/Map.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ export default function MapWrapper({
const { mapContext, setMapContext } = useContext(MapContext);

// Refs
const isInitialMountLocation = useRef(true);
const isInitialMountLocation = useRef('not set');
const isInitialMountRoute = useRef(true);
const mapElement = useRef();
const mapRef = useRef();
Expand Down Expand Up @@ -411,13 +411,19 @@ export default function MapWrapper({
locationPinRef
);

if (isInitialMountLocation.current) {
if (isInitialMountLocation.current === 'not set') { // first run of this effector
// store the initial searchLocationFrom.[0].label so that subsequent
// runs can be evaluated to detect change in the search from
isInitialMountLocation.current = searchLocationFrom[0].label;
} else if (isInitialMountLocation.current !== searchLocationFrom[0].label) {
// only zoomPan on a real change in the search location from; this makes
// this effector idempotent wrt state
isInitialMountLocation.current = false;

} else {
// Don't center/remove existing overlay on first load
setZoomPan(mapView, 9, fromLonLat(searchLocationFrom[0].geometry.coordinates));
}
} else {
// initial location was set, so no need to prevent pan/zoom
isInitialMountLocation.current = false;
}
}, [searchLocationFrom]);

Expand Down

0 comments on commit c1d6f43

Please sign in to comment.