WIP: Plus-Icon bei überlappende Marker ausblenden wenn nur eine oder keine sichtbar geschaltet werden in Checkboxen
This commit is contained in:
@@ -78,24 +78,34 @@ export const restoreMapSettings = (map) => {
|
||||
};
|
||||
|
||||
// Now update checkOverlappingMarkers to check if oms is initialized
|
||||
// Globales Array, um Plus-Icons zu speichern
|
||||
let plusMarkers = [];
|
||||
|
||||
export const checkOverlappingMarkers = (map, markers, plusIcon) => {
|
||||
const overlappingGroups = {};
|
||||
|
||||
// Gruppiere Marker basierend auf ihrer Position
|
||||
markers.forEach((marker) => {
|
||||
const latlngStr = marker.getLatLng().toString();
|
||||
if (overlappingGroups[latlngStr]) {
|
||||
overlappingGroups[latlngStr].push(marker);
|
||||
} else {
|
||||
overlappingGroups[latlngStr] = [marker];
|
||||
if (map.hasLayer(marker)) { // Überprüfen, ob der Marker sichtbar ist
|
||||
const latlngStr = marker.getLatLng().toString();
|
||||
if (overlappingGroups[latlngStr]) {
|
||||
overlappingGroups[latlngStr].push(marker);
|
||||
} else {
|
||||
overlappingGroups[latlngStr] = [marker];
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// Entferne alte Plus-Icons
|
||||
plusMarkers.forEach((plusMarker) => map.removeLayer(plusMarker));
|
||||
plusMarkers = [];
|
||||
|
||||
// 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 }).addTo(map);
|
||||
plusMarkers.push(plusMarker); // Speichere das Plus-Icon
|
||||
|
||||
plusMarker.on("click", (e) => {
|
||||
const clickedLatLng = e.latlng;
|
||||
@@ -115,8 +125,15 @@ export const checkOverlappingMarkers = (map, markers, plusIcon) => {
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// Entferne alle Plus-Icons, wenn keine Marker sichtbar sind
|
||||
if (Object.keys(overlappingGroups).length === 0) {
|
||||
plusMarkers.forEach((plusMarker) => map.removeLayer(plusMarker));
|
||||
plusMarkers = [];
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
export const handlePlusIconClick = (map, markers, oms, clickedLatLng) => {
|
||||
// Debugging-Ausgabe
|
||||
console.log("Plus-Icon Position:", clickedLatLng);
|
||||
|
||||
Reference in New Issue
Block a user