Skip to content

Commit

Permalink
feat: clustering
Browse files Browse the repository at this point in the history
  • Loading branch information
tyleryy committed Oct 9, 2024
1 parent 6e67e06 commit bdaaf38
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 8 deletions.
1 change: 1 addition & 0 deletions packages/web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"react-ga4": "^2.1.0",
"react-icons": "^4.10.1",
"react-leaflet": "^4.2.1",
"react-leaflet-cluster": "^2.1.0",
"react-resizable": "^3.0.5",
"react-resizable-panels": "^0.0.53",
"react-router-dom": "^6.11.2",
Expand Down
3 changes: 1 addition & 2 deletions packages/web/src/components/Home/Home.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -726,8 +726,7 @@ export default function Home() {
left={10}
bottom={10}
></Flex>
<FeedbackButtonMobile />

<FeedbackButtonMobile />
<Map
newAddedItem={newAddedItem}
setNewAddedItem={setNewAddedItem}
Expand Down
16 changes: 10 additions & 6 deletions packages/web/src/components/Map/Map.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import { UserAuth } from "../../context/AuthContext";
import axios from "axios";

import { filterItem } from "../../utils/Utils.js";
import MarkerClusterGroup from 'react-leaflet-cluster'

/**
* Map is uses react-leaflet's API to communicate user actions to map entities and information
Expand Down Expand Up @@ -133,8 +134,8 @@ export default function Map({
);

const markersData = results.length > 0 ? results : data;
const allMarkers = markersData.filter(filterItemCallback).map((item) => {
return (
const allMarkers = useMemo(() => {
return markersData.filter(filterItemCallback).map((item) => (
<Marker
key={item.key}
position={item.location}
Expand All @@ -151,8 +152,8 @@ export default function Map({
: (iconsMap[item.type] || iconsMap["others"])[item.islost]
}
></Marker>
);
});
));
}, [markersData, filterItemCallback, onOpen, setItemData, setFocusLocation]);

// moves map when focusLocation state changes
function MapFocusLocation({ location }) {
Expand Down Expand Up @@ -353,8 +354,11 @@ export default function Map({
{!isEdit && (
<MapFocusLocation location={focusLocation} search={search} />
)}
{!isEdit}
{!isEdit && allMarkers}
{!isEdit && (
<MarkerClusterGroup chunkedLoading>
{allMarkers}
</MarkerClusterGroup>
)}

{isEdit && <NewItemMarker />}
{showDonut && focusLocation && (
Expand Down
26 changes: 26 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit bdaaf38

Please sign in to comment.