Bug Fix
Der Bug in der Anwendung tritt auf, wenn eine Checkbox angeklickt wird und unerwartet eine Zoom-Funktion ausgelöst wird. Dies geschieht nach einer Auswahl aus einem Dropdown-Menü. Wenn eine Option im Dropdown-Menü ausgewählt wird, scheint der darauf folgende Klick auf eine Checkbox dazu zu führen, dass auf die zuletzt ausgewählte Position im Dropdown-Menü gezoomt wird. Die Zustandsänderungen oder Event-Handler in der Anwendung interagieren auf eine nicht beabsichtigte Weise, wodurch diese unerwünschte Zoom-Aktion aktiviert wird. sogar wenn Info geklickt wird.
This commit is contained in:
55
components/PoiUtils.js
Normal file
55
components/PoiUtils.js
Normal file
@@ -0,0 +1,55 @@
|
||||
import L from "leaflet";
|
||||
|
||||
// Funktion, um POI Markers zu erstellen
|
||||
export const createPoiMarkers = (poiData, iconPath) => {
|
||||
return poiData.map((location) => {
|
||||
return L.marker([location.latitude, location.longitude], {
|
||||
icon: L.icon({
|
||||
iconUrl: iconPath,
|
||||
iconSize: [25, 41],
|
||||
iconAnchor: [12, 41],
|
||||
popupAnchor: [1, -34],
|
||||
draggable: true,
|
||||
}),
|
||||
id: location.idPoi,
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
// Funktion zum Hinzufügen von Markern zur Karte und zum Umgang mit Events
|
||||
export const addMarkersToMap = (markers, map, layerGroup) => {
|
||||
markers.forEach((marker) => {
|
||||
marker.addTo(layerGroup);
|
||||
marker.on("mouseover", () => marker.openPopup());
|
||||
marker.on("mouseout", () => marker.closePopup());
|
||||
marker.on("dragend", (e) => {
|
||||
const newLat = e.target.getLatLng().lat;
|
||||
const newLng = e.target.getLatLng().lng;
|
||||
const markerId = e.target.options.id;
|
||||
updateLocationInDatabase(markerId, newLat, newLng);
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
// Funktion zum Aktualisieren der Standorte in der Datenbank
|
||||
export const updateLocationInDatabase = async (
|
||||
id,
|
||||
newLatitude,
|
||||
newLongitude
|
||||
) => {
|
||||
const response = await fetch("/api/updateLocation", {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify({
|
||||
id,
|
||||
latitude: newLatitude,
|
||||
longitude: newLongitude,
|
||||
}),
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
console.error("Fehler beim Aktualisieren der Position");
|
||||
}
|
||||
};
|
||||
|
||||
// Weitere Funktionen können hier hinzugefügt werden
|
||||
Reference in New Issue
Block a user