diff --git a/utils/mapUtils.js b/utils/mapUtils.js index 3c3938b59..a7dae6bda 100644 --- a/utils/mapUtils.js +++ b/utils/mapUtils.js @@ -79,15 +79,9 @@ 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 + // Gruppiere Marker basierend auf ihrer Position markers.forEach((marker) => { const latlngStr = marker.getLatLng().toString(); if (overlappingGroups[latlngStr]) { @@ -97,18 +91,47 @@ export const checkOverlappingMarkers = (map, markers, plusIcon) => { } }); - // Add plus markers at coordinates where overlaps occur + // Füge Plus-Icons für überlappende Marker hinzu 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); - //localStorage benutzen statt console.log - //console.log("Adding plus icon marker at", latLng); - localStorage.setItem("Adding plus icon marker at", plusMarker); + const plusMarker = L.marker(latLng, { icon: plusIcon }).addTo(map); + + plusMarker.on("click", (e) => { + const clickedLatLng = e.latlng; + + // Finde nahegelegene Marker (50 Pixel als Beispielradius) + const nearbyMarkers = markers.filter((marker) => map.distance(marker.getLatLng(), clickedLatLng) < 50); + + console.log("Nearby Markers for Plus Icon:", nearbyMarkers); + + if (nearbyMarkers.length > 0) { + // Simuliere einen Klick auf jeden Marker + nearbyMarkers.forEach((marker) => { + marker.fire("click"); + }); + } else { + console.log("Keine Marker gefunden."); + } + }); } } - //localStorage benutzen statt console.log - //console.log("overlappingGroups", overlappingGroups); - localStorage.setItem("overlappingGroups", overlappingGroups); +}; + +export const handlePlusIconClick = (map, markers, oms, clickedLatLng) => { + // Debugging-Ausgabe + console.log("Plus-Icon Position:", clickedLatLng); + + // Finde Marker in der Nähe der Klickposition + const nearbyMarkers = markers.filter((marker) => map.distance(marker.getLatLng(), clickedLatLng) < 50); + + // Debugging-Ausgabe + console.log("Gefundene Marker in der Nähe:", nearbyMarkers); + + if (oms && nearbyMarkers.length > 0) { + // Spiderfy die gefundenen Marker + oms.spiderfy(nearbyMarkers); + } else { + console.log("Keine überlappenden Marker gefunden."); + } };