google-map-react- Converts the native Google Maps API into a React component.
- Vendor docs, pt 2.
redux-toolkit- Manages the view state of the map.
- Includes abstractions like
createAsyncThunkto handle asynchronous requests, signaling loading states.
components/map/MapPage.js- Connects to the Redux store and populates
Mapwith location and cluster data.
- Connects to the Redux store and populates
redux/mapSlice.js- Actions and reducers for changing internal view state of the map.
- Actions for fetching locations and clusters from the API.
redux/viewChange.js- Primary event handler called when the map loads or is moved by the user.
- Dispatches actions to update the map view and fetch data.
Usage:
<GoogleMapReact
...
center={view.center}
zoom={view.zoom}
onChange={onViewChange}
...
>GoogleMapReact is a controlled component, meaning the view state is driven by the center and zoom props. We set them up initially, and then let the map keep its center and zoom.
- Page Loads
- Default or URL-parsed center and zoom are passed.
GoogleMapReactcallsonChangeto provide map bounds.MapPagedispatches actions with the new view:- Updates URL.
- Stops tracking geolocation if the user moved too far.
- Fetches filter counts if the filter is open.
- User Moves the Map
GoogleMapReactcallsonChangewith the new view.
- User Clicks a Cluster
MapcallsonClusterClick.MapPagedispatchesclusterClickaction inmapSlice.js:- Changes zoom in the internal view state.
GoogleMapReactcallsonChangewith the new zoom.
- Other App-Initiated Actions
- Similar to user interactions, actions initiated by the app change the internal view state, triggering
onChangeinGoogleMapReact.
- Similar to user interactions, actions initiated by the app change the internal view state, triggering