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
createAsyncThunk
to handle asynchronous requests, signaling loading states.
components/map/MapPage.js
- Connects to the Redux store and populates
Map
with 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.
GoogleMapReact
callsonChange
to provide map bounds.MapPage
dispatches 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
GoogleMapReact
callsonChange
with the new view.
- User Clicks a Cluster
Map
callsonClusterClick
.MapPage
dispatchesclusterClick
action inmapSlice.js
:- Changes zoom in the internal view state.
GoogleMapReact
callsonChange
with the new zoom.
- Other App-Initiated Actions
- Similar to user interactions, actions initiated by the app change the internal view state, triggering
onChange
inGoogleMapReact
.
- Similar to user interactions, actions initiated by the app change the internal view state, triggering