Skip to content

Commit 36fe5ae

Browse files
committed
multi-marker support and clustering
1 parent 5355187 commit 36fe5ae

File tree

5 files changed

+53
-16
lines changed

5 files changed

+53
-16
lines changed

package.json

+2
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@
5555
"jspdf-autotable": "^3.8.2",
5656
"leaflet": "^1.9.4",
5757
"leaflet-defaulticon-compatibility": "^0.1.2",
58+
"leaflet.markercluster": "^1.5.3",
5859
"lodash.isequal": "4.5.0",
5960
"material-react-table": "^3.0.1",
6061
"monaco-editor": "^0.52.0",
@@ -76,6 +77,7 @@
7677
"react-html-parser": "^2.0.2",
7778
"react-i18next": "12.1.4",
7879
"react-leaflet": "4.2.1",
80+
"react-leaflet-markercluster": "^4.2.1",
7981
"react-markdown": "8.0.5",
8082
"react-media-hook": "^0.5.0",
8183
"react-papaparse": "^4.4.0",

src/components/CippComponents/CippGeoLocation.jsx

+4-3
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ export default function CippGeoLocation({ ipAddress, cardProps }) {
3636
{markerProperties.map((key) => (
3737
<div key={key}>
3838
<strong>{getCippTranslation(key)}:</strong>{" "}
39-
{getCippFormatting(locationInfo[key], key)}
39+
{getCippFormatting(result[key], key)}
4040
</div>
4141
))}
4242
</div>
@@ -63,9 +63,10 @@ export default function CippGeoLocation({ ipAddress, cardProps }) {
6363
<Grid item size={{ xs: 12, sm: 8 }}>
6464
{locationInfo && locationInfo.lat && locationInfo.lon && (
6565
<CippMap
66-
position={[locationInfo.lat, locationInfo.lon]}
66+
markers={[
67+
{ position: [locationInfo.lat, locationInfo.lon], popup: markerPopupContents },
68+
]}
6769
zoom={11}
68-
markerPopupContents={markerPopupContents}
6970
mapSx={{ height: "400px", width: "100%" }}
7071
/>
7172
)}
+29-8
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,46 @@
11
import "leaflet/dist/leaflet.css";
2+
import "react-leaflet-markercluster/styles";
23
import "leaflet-defaulticon-compatibility/dist/leaflet-defaulticon-compatibility.webpack.css";
34
import "leaflet-defaulticon-compatibility";
4-
5+
import { useEffect, useRef } from "react";
56
import { MapContainer, Marker, Popup, TileLayer } from "react-leaflet";
7+
import MarkerClusterGroup from "react-leaflet-markercluster";
68

79
export default function CippMap({
8-
position,
9-
zoom,
10-
markerPopupContents,
10+
markers = [],
11+
zoom = 11,
1112
mapSx = { height: "400px", width: "600px" },
1213
...props
1314
}) {
15+
const mapRef = useRef();
16+
17+
useEffect(() => {
18+
if (mapRef.current && markers.length > 1) {
19+
const bounds = markers.map((marker) => marker.position);
20+
mapRef.current.fitBounds(bounds, { padding: [25, 25] });
21+
}
22+
}, [markers]);
23+
1424
return (
15-
<MapContainer center={position} zoom={zoom} scrollWheelZoom={true} style={mapSx} {...props}>
25+
<MapContainer
26+
center={markers?.[0]?.position ?? [0, 0]}
27+
zoom={zoom}
28+
scrollWheelZoom={true}
29+
style={mapSx}
30+
{...props}
31+
ref={mapRef}
32+
>
1633
<TileLayer
1734
attribution='&copy; <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors'
1835
url="https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png"
1936
/>
20-
<Marker position={position}>
21-
<Popup>{markerPopupContents}</Popup>
22-
</Marker>
37+
<MarkerClusterGroup>
38+
{markers.map((marker, index) => (
39+
<Marker key={index} position={marker.position}>
40+
{marker?.popup && <Popup>{marker.popup}</Popup>}
41+
</Marker>
42+
))}
43+
</MarkerClusterGroup>
2344
</MapContainer>
2445
);
2546
}

src/pages/tenant/administration/audit-logs/log.js

-2
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@ import dynamic from "next/dynamic";
1111
import CippGeoLocation from "../../../../components/CippComponents/CippGeoLocation";
1212
import { Grid } from "@mui/system";
1313

14-
const CippMap = dynamic(() => import("/src/components/CippComponents/CippMap"), { ssr: false });
15-
1614
const Page = () => {
1715
const router = useRouter();
1816
const { id } = router.query;

yarn.lock

+18-3
Original file line numberDiff line numberDiff line change
@@ -1529,7 +1529,7 @@
15291529
resolved "https://registry.yarnpkg.com/@popperjs/core/-/core-2.11.8.tgz#6b79032e760a0899cd4204710beede972a3a185f"
15301530
integrity sha512-P1st0aksCrn9sGZhp8GMYwBnQsbvAWsZAX44oXNNvLHGqAOcoVxmjZiohstwQ7SqKnbR47akdNi+uleWD8+g6A==
15311531

1532-
"@react-leaflet/core@^2.1.0":
1532+
"@react-leaflet/core@^2.0.0", "@react-leaflet/core@^2.1.0":
15331533
version "2.1.0"
15341534
resolved "https://registry.yarnpkg.com/@react-leaflet/core/-/core-2.1.0.tgz#383acd31259d7c9ae8fb1b02d5e18fe613c2a13d"
15351535
integrity sha512-Qk7Pfu8BSarKGqILj4x7bCSZ1pjuAPZ+qmRwH5S7mDS91VSbVVsJSrW4qA+GPrro8t69gFYVMWb1Zc4yFmPiVg==
@@ -4508,7 +4508,12 @@ leaflet-defaulticon-compatibility@^0.1.2:
45084508
resolved "https://registry.yarnpkg.com/leaflet-defaulticon-compatibility/-/leaflet-defaulticon-compatibility-0.1.2.tgz#f5e1a5841aeab9d1682d17887348855a741b3c2a"
45094509
integrity sha512-IrKagWxkTwzxUkFIumy/Zmo3ksjuAu3zEadtOuJcKzuXaD76Gwvg2Z1mLyx7y52ykOzM8rAH5ChBs4DnfdGa6Q==
45104510

4511-
leaflet@^1.9.4:
4511+
leaflet.markercluster@^1.5.3:
4512+
version "1.5.3"
4513+
resolved "https://registry.yarnpkg.com/leaflet.markercluster/-/leaflet.markercluster-1.5.3.tgz#9cdb52a4eab92671832e1ef9899669e80efc4056"
4514+
integrity sha512-vPTw/Bndq7eQHjLBVlWpnGeLa3t+3zGiuM7fJwCkiMFq+nmRuG3RI3f7f4N4TDX7T4NpbAXpR2+NTRSEGfCSeA==
4515+
4516+
leaflet@^1.8.0, leaflet@^1.9.4:
45124517
version "1.9.4"
45134518
resolved "https://registry.yarnpkg.com/leaflet/-/leaflet-1.9.4.tgz#23fae724e282fa25745aff82ca4d394748db7d8d"
45144519
integrity sha512-nxS1ynzJOmOlHp+iL3FyWqK89GtNL8U8rvlMOsQdTTssxZwCXh8N2NB3GDQOL+YR3XnWyZAxwQixURb+FA74PA==
@@ -5624,7 +5629,17 @@ react-is@^18.0.0, react-is@^18.3.1:
56245629
resolved "https://registry.yarnpkg.com/react-is/-/react-is-18.3.1.tgz#e83557dc12eae63a99e003a46388b1dcbb44db7e"
56255630
integrity sha512-/LLMVyas0ljjAtoYiPqYiL8VWXzUUdThrmU5+n20DZv+a+ClRoevUzw5JxU+Ieh5/c87ytoTBV9G1FiKfNJdmg==
56265631

5627-
5632+
react-leaflet-markercluster@^4.2.1:
5633+
version "4.2.1"
5634+
resolved "https://registry.yarnpkg.com/react-leaflet-markercluster/-/react-leaflet-markercluster-4.2.1.tgz#74a9501925f5920585aa700ec3790c9cca48012a"
5635+
integrity sha512-lRJwCMGJVKXOKdP/dZIxszfHXjJaf8BpP2E+cNIYx5XxvqFj7NADG1HeK1nouNUgMcXVhqpZejiV6wPxwCibJw==
5636+
dependencies:
5637+
"@react-leaflet/core" "^2.0.0"
5638+
leaflet "^1.8.0"
5639+
leaflet.markercluster "^1.5.3"
5640+
react-leaflet "^4.0.0"
5641+
5642+
[email protected], react-leaflet@^4.0.0:
56285643
version "4.2.1"
56295644
resolved "https://registry.yarnpkg.com/react-leaflet/-/react-leaflet-4.2.1.tgz#c300e9eccaf15cb40757552e181200aa10b94780"
56305645
integrity sha512-p9chkvhcKrWn/H/1FFeVSqLdReGwn2qmiobOQGO3BifX+/vV/39qhY8dGqbdcPh1e6jxh/QHriLXr7a4eLFK4Q==

0 commit comments

Comments
 (0)