bindTooltip zu Marker hinzugefügt über Hover Effekt

This commit is contained in:
ISA
2024-04-16 09:26:49 +02:00
parent e1f03c53e2
commit ddd8ae8a3c

View File

@@ -68,11 +68,11 @@ const MapComponent = ({ locations, onLocationUpdate }) => {
useEffect(() => {
if (map && GisStationsStaticDistrict.length > 0) {
// Zuerst alte Marker entfernen
map.eachLayer((layer) => {
/* map.eachLayer((layer) => {
if (layer instanceof L.Marker) {
map.removeLayer(layer);
}
});
}); */
// Neue Marker für jede Station hinzufügen
GisStationsStaticDistrict.forEach((station) => {
@@ -91,6 +91,10 @@ const MapComponent = ({ locations, onLocationUpdate }) => {
marker
.bindPopup(`<b>${station.LD_Name}</b><br>${station.Device}`)
.openPopup();
marker.bindTooltip(station.LD_Name, {
permanent: false,
direction: "top",
});
});
}
}, [map, GisStationsStaticDistrict]); // Abhängigkeiten hinzufügen, um sicherzustellen, dass Effekt bei Änderungen neu ausgeführt wird
@@ -274,6 +278,10 @@ const MapComponent = ({ locations, onLocationUpdate }) => {
marker.bindPopup(
`<b>${location.description || "Unbekannt"}</b><br>Type: ${location.idPoiTyp || "N/A"}<br>Lat: ${latitude.toFixed(5)}, Lng: ${longitude.toFixed(5)}`
);
marker.bindTooltip(location.description, {
permanent: false,
direction: "top",
});
marker.on("dragend", function (e) {
const newLat = e.target.getLatLng().lat;