From 6f477092562ccb9bf8d30b61eb8658b627845746 Mon Sep 17 00:00:00 2001 From: Ismail Ali Date: Sun, 9 Mar 2025 18:46:38 +0100 Subject: [PATCH] fix: Automatische Aktualisierung von Spiderfy/Unspiderfy im Intervall MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - `map.fire("click")` im `setInterval()` hinzugefügt, um Linien sofort auszublenden - Spiderfy/Unspiderfy wird nun regelmäßig aktualisiert, ohne manuelles Klicken - Debugging-Log hinzugefügt, um Klick-Event zu überwachen --- components/mainComponent/MapComponent.js | 7 ++++- config/appVersion.js | 2 +- lib/OverlappingMarkerSpiderfier.js | 39 ++++++++++++++++++------ 3 files changed, 36 insertions(+), 12 deletions(-) diff --git a/components/mainComponent/MapComponent.js b/components/mainComponent/MapComponent.js index 6086c5998..f6ef66dcb 100644 --- a/components/mainComponent/MapComponent.js +++ b/components/mainComponent/MapComponent.js @@ -868,7 +868,12 @@ const MapComponent = ({ locations, onLocationUpdate, lineCoordinates }) => { // Setze ein Intervall für regelmäßige Updates const intervalId = setInterval(() => { updateAllMarkers(); - }, 20000); // 20 Sekunden + + if (map) { + console.log("🔥 Automatischer Klick-Event ausgelöst, um Spiderfy zu aktualisieren."); + map.fire("click"); + } + }, 20000); // Aufräumen bei Komponentenentladung return () => { diff --git a/config/appVersion.js b/config/appVersion.js index 25b7a96f2..2d27093f8 100644 --- a/config/appVersion.js +++ b/config/appVersion.js @@ -1,2 +1,2 @@ // /config/appVersion -export const APP_VERSION = "1.1.36"; +export const APP_VERSION = "1.1.37"; diff --git a/lib/OverlappingMarkerSpiderfier.js b/lib/OverlappingMarkerSpiderfier.js index 0e1747459..5093ae240 100644 --- a/lib/OverlappingMarkerSpiderfier.js +++ b/lib/OverlappingMarkerSpiderfier.js @@ -67,38 +67,57 @@ export class OverlappingMarkerSpiderfier { return distance < this.nearbyDistance && marker !== m; }); } - + //--------------------------------------------------------------------------------------------- spiderfy(markers) { const centerPt = this.map.latLngToLayerPoint(markers[0].getLatLng()); + markers.forEach((marker, i) => { const angle = this.circleStartAngle + (i * 2 * Math.PI) / markers.length; const legLength = this.circleFootSeparation * (2 + i / markers.length); - const newPt = L.point( - centerPt.x + legLength * Math.cos(angle), - centerPt.y + legLength * Math.sin(angle) - ); + const newPt = L.point(centerPt.x + legLength * Math.cos(angle), centerPt.y + legLength * Math.sin(angle)); const newLatLng = this.map.layerPointToLatLng(newPt); if (!marker._oms) { - marker._oms = {}; // Stellt sicher, dass _oms ein Objekt ist + marker._oms = {}; } - // Speichert die aktuelle Position, bevor sie verändert wird marker._oms.usualPosition = marker.getLatLng(); - marker._oms.spidered = true; // Markiert, dass der Marker gespiderfied ist + marker._oms.spidered = true; + + // Zeichne eine Linie zwischen ursprünglicher und neuer Position + const leg = L.polyline([marker._oms.usualPosition, newLatLng], { + color: this.legColors.usual, + weight: this.legWeight, + }).addTo(this.map); + + marker._oms.leg = leg; // Speichert die Linie im Marker-Objekt marker.setLatLng(newLatLng); marker.setZIndexOffset(1000); }); } + + //--------------------------------------------------------------------------------------------- unspiderfy() { this.markers.forEach((marker) => { if (marker._oms && marker._oms.spidered) { - // Setzt den Marker nur dann zurück, wenn er gespiderfied war + // Falls eine Linie existiert, entferne sie aus der Karte + if (marker._oms.leg) { + this.map.removeLayer(marker._oms.leg); + marker._oms.leg = null; + } + marker.setLatLng(marker._oms.usualPosition); marker.setZIndexOffset(0); - marker._oms.spidered = false; // Setzt zurück, dass der Marker nicht mehr gespiderfied ist + marker._oms.spidered = false; } }); + // 🔥 Künstliches Click-Event auslösen, um die UI zu aktualisieren + setTimeout(() => { + this.map.fire("click"); + console.log("Click-Event ausgelöst in OverlappingMarkerspiderfier.js in unspiderfy "); + }, 10); // Kurze Verzögerung, um sicherzustellen, dass die UI neu gerendert wird } + + //--------------------------------------------------------------------------------------------- }