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:
@@ -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);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user