Skip to content

Commit

Permalink
CORE-4887 Clean
Browse files Browse the repository at this point in the history
  • Loading branch information
valeriibudko committed May 22, 2024
1 parent e4d952b commit 82c1bb5
Showing 1 changed file with 12 additions and 16 deletions.
28 changes: 12 additions & 16 deletions modules/map/map.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import React, { useRef, useEffect } from 'react'
import L from 'leaflet'
import { MarkerClusterGroup } from 'leaflet.markercluster'

import styles from './styles.module.css'

Check failure on line 4 in modules/map/map.jsx

View workflow job for this annotation

GitHub Actions / Code quality

'styles' is defined but never used

Expand All @@ -19,8 +18,7 @@ const markerIcon = L.icon({
const CustomMap = ({ locations }) => {
const markersData = locations

const mapRef = useRef(null);
const markerClusterGroupRef = useRef(null);
const mapRef = useRef(null)

useEffect(() => {
// Initialize the map
Expand All @@ -30,20 +28,18 @@ const CustomMap = ({ locations }) => {
zoom: 3, // Default zoom level
layers: [
L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
attribution: '&copy; <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors'
})
]
});
attribution:
'&copy; <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors',
}),
],
})
}

// Create and add markers
const markers = markersData.map(markerData => {

const markers = markersData.map((markerData) => {
const { name, href, latitude, longitude } = markerData

const latLng = new L.LatLng(latitude, longitude);

const marker = L.marker(latLng).addTo(mapRef.current);
const latLng = new L.LatLng(latitude, longitude)
const marker = L.marker(latLng).addTo(mapRef.current)
if (href) {
marker.bindPopup(
`<a
Expand All @@ -57,12 +53,12 @@ const CustomMap = ({ locations }) => {
} else marker.bindPopup(name)

// marker.bindPopup(name);
return marker;
});
return marker
})

return () => {
// Cleanup the map and markers
markers.forEach(marker => marker.remove());
markers.forEach((marker) => marker.remove())
mapRef.current.remove()
mapRef.current = null
}
Expand Down

0 comments on commit 82c1bb5

Please sign in to comment.