wip: Dynamische Layers /Geräte Gruppen Erkennung , overlapping funktioniert es noch nicht
This commit is contained in:
@@ -22,12 +22,15 @@ export const restoreMapSettings = (map) => {
|
||||
let plusMarkers = [];
|
||||
|
||||
export const checkOverlappingMarkers = (map, markers, plusIcon) => {
|
||||
if (!Array.isArray(markers)) {
|
||||
console.warn("⚠️ checkOverlappingMarkers erwartet ein Array, aber erhielt:", markers);
|
||||
return;
|
||||
}
|
||||
|
||||
const overlappingGroups = {};
|
||||
|
||||
// Gruppiere Marker basierend auf ihrer Position
|
||||
markers.forEach((marker) => {
|
||||
if (map.hasLayer(marker)) {
|
||||
// Überprüfen, ob der Marker sichtbar ist
|
||||
const latlngStr = marker.getLatLng().toString();
|
||||
if (overlappingGroups[latlngStr]) {
|
||||
overlappingGroups[latlngStr].push(marker);
|
||||
@@ -37,37 +40,27 @@ export const checkOverlappingMarkers = (map, markers, plusIcon) => {
|
||||
}
|
||||
});
|
||||
|
||||
// Entferne alte Plus-Icons
|
||||
// alte PlusIcons entfernen
|
||||
plusMarkers.forEach((plusMarker) => map.removeLayer(plusMarker));
|
||||
plusMarkers = [];
|
||||
|
||||
// Füge Plus-Icons für überlappende Marker hinzu
|
||||
// neue PlusIcons hinzufügen
|
||||
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
|
||||
plusMarkers.push(plusMarker);
|
||||
|
||||
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 nur auf den ersten Marker
|
||||
nearbyMarkers[0].fire("click");
|
||||
console.log("Clicked on nearby Marker[0]:", nearbyMarkers[0]);
|
||||
} else {
|
||||
console.log("Keine Marker gefunden.");
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// Entferne alle Plus-Icons, wenn keine Marker sichtbar sind
|
||||
if (Object.keys(overlappingGroups).length === 0) {
|
||||
plusMarkers.forEach((plusMarker) => map.removeLayer(plusMarker));
|
||||
plusMarkers = [];
|
||||
|
||||
Reference in New Issue
Block a user