Skip to content

Commit

Permalink
Fixes a map panning issue from issue #527
Browse files Browse the repository at this point in the history
This fixes the issue where opening a site, then clicking "Near Me", then
closing the info modal was panning back to the prior site, whereas it
should have stayed at the "Near Me" site. This is "issue C" as discussed
in the comments of GitHub issue #527.
  • Loading branch information
ravicodelabs committed Oct 6, 2024
1 parent 3c1bc92 commit 30d33bd
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 14 deletions.
26 changes: 14 additions & 12 deletions src/components/ReactGoogleMaps/ReactGoogleMaps.js
Original file line number Diff line number Diff line change
Expand Up @@ -214,9 +214,6 @@ export const ReactGoogleMaps = ({ google }) => {
state => state.filterMarkers.showingInfoWindow
);
const toolbarModal = useSelector(state => state.filterMarkers.toolbarModal);

const [currentLat, setCurrentLat] = useState(CITY_HALL_COORDINATES.latitude);
const [currentLon, setCurrentLon] = useState(CITY_HALL_COORDINATES.longitude);
const [zoom, setZoom] = useState(16);
const [searchedTap, setSearchedTap] = useState(null);
const [map, setMap] = useState(null);
Expand All @@ -237,8 +234,6 @@ export const ReactGoogleMaps = ({ google }) => {
const fetchCoordinates = async () => {
try {
const position = await getCoordinates();
setCurrentLat(position.coords.latitude);
setCurrentLon(position.coords.longitude);
dispatch(
setUserLocation({
lat: position.coords.latitude,
Expand Down Expand Up @@ -268,19 +263,26 @@ export const ReactGoogleMaps = ({ google }) => {
})
);
dispatch(setSelectedPlace(resource));
setCurrentLat(resource.latitude);
setCurrentLon(resource.longitude);
dispatch(
setMapCenter({
lat: resource.latitude,
lng: resource.longitude
})
)
markerProps.map.panTo({ lat: resource.latitude, lng: resource.longitude });

};

const onReady = (_, map) => {
setMap(map);
};

const searchForLocation = location => {
setCurrentLat(location.lat);
setCurrentLon(location.lng);
dispatch(
setMapCenter({
lat: location.lat,
lng: location.lng
})
)
setZoom(16);
setSearchedTap({ lat: location.lat, lng: location.lng });
};
Expand Down Expand Up @@ -351,8 +353,8 @@ export const ReactGoogleMaps = ({ google }) => {
fullscreenControl={false}
onReady={onReady}
center={{
lat: currentLat,
lng: currentLon
lat: mapCenter.lat,
lng: mapCenter.lng
}}
filterTags={appliedFilterTags}
>
Expand Down
10 changes: 8 additions & 2 deletions src/components/Toolbar/Toolbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
TOOLBAR_MODAL_NONE,
TOOLBAR_MODAL_RESOURCE,
TOOLBAR_MODAL_SEARCH,
setMapCenter,
setSelectedPlace,
setToolbarModal,
toggleInfoWindow,
Expand Down Expand Up @@ -111,10 +112,15 @@ function Toolbar({ map }) {
lon: userLocation.lng
});

if (!closest) console.log("no closest found!")
// if (!closest) console.log("no closest found!")

if (!closest) return;

dispatch(
setMapCenter({
lat: closest.latitude,
lng: closest.longitude
})
)
dispatch(setSelectedPlace(closest));
map.panTo({
lat: closest.latitude,
Expand Down

0 comments on commit 30d33bd

Please sign in to comment.