refactor: Move checkOverlappingMarkers to utils and update import in MapComponent

- Moved checkOverlappingMarkers function from MapComponent.js to a new file in /utils/mapUtils.js for better separation of concerns.
- Updated the import statement in MapComponent.js to reflect the new location of checkOverlappingMarkers.
This commit is contained in:
ISA
2024-07-11 10:44:40 +02:00
parent 070065e090
commit 18f0f8266b
2 changed files with 38 additions and 37 deletions

View File

@@ -77,3 +77,35 @@ export const restoreMapSettings = (map) => {
}
}
};
// Now update checkOverlappingMarkers to check if oms is initialized
export const checkOverlappingMarkers = (map, markers, plusIcon) => {
// Ensure markers is always an array
if (!Array.isArray(markers)) {
//console.error("The `markers` argument is not an array:", markers);
return;
}
const overlappingGroups = {};
// Group markers by coordinates as strings
markers.forEach((marker) => {
const latlngStr = marker.getLatLng().toString();
if (overlappingGroups[latlngStr]) {
overlappingGroups[latlngStr].push(marker);
} else {
overlappingGroups[latlngStr] = [marker];
}
});
// Add plus markers at coordinates where overlaps occur
for (const coords in overlappingGroups) {
if (overlappingGroups[coords].length > 1) {
const latLng = L.latLng(coords.match(/[-.\d]+/g).map(Number));
const plusMarker = L.marker(latLng, { icon: plusIcon });
plusMarker.addTo(map);
//console.log("Adding plus icon marker at", latLng);
}
}
};