fix: Automatische Aktualisierung von Spiderfy/Unspiderfy im Intervall
- `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
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user