refactor: POI-Daten vollständig in Redux integriert

- useFetchPoiData.js entfernt
- Neue Redux-Slices für POI-Typen und POI-Icons erstellt
- Neue Services und Thunks hinzugefügt
- fetch-Aufrufe durch zentralisierte Redux-Logik ersetzt
- store.js aktualisiert und neue States registriert
This commit is contained in:
ISA
2025-05-23 11:14:13 +02:00
parent 08679761fb
commit 0a1c0e5fbe
20 changed files with 304 additions and 337 deletions

View File

@@ -0,0 +1,68 @@
// components/CoordinatePopup.js
import React from "react";
const CoordinatePopup = ({ isOpen, coordinates, onClose }) => {
if (!isOpen) return null;
const copyToClipboard = () => {
if (typeof navigator !== "undefined" && navigator.clipboard) {
navigator.clipboard
.writeText(coordinates)
.then(() => {
alert("Koordinaten kopiert!");
})
.catch((err) => {
console.error("Clipboard-API Fehler:", err);
fallbackCopyToClipboard(coordinates);
});
} else {
fallbackCopyToClipboard(coordinates);
}
};
const fallbackCopyToClipboard = (text) => {
const textArea = document.createElement("textarea");
textArea.value = text;
document.body.appendChild(textArea);
textArea.focus();
textArea.select();
try {
const successful = document.execCommand("copy");
if (successful) {
alert("Koordinaten kopiert!");
} else {
alert("Kopieren fehlgeschlagen (Fallback).");
}
} catch (err) {
alert("Kopieren fehlgeschlagen: " + err.message);
}
document.body.removeChild(textArea);
};
return (
<div
className="fixed inset-0 bg-black bg-opacity-30 flex justify-center z-50"
onClick={onClose}
style={{
alignItems: "flex-start",
paddingTop: "5px",
}}
>
<div className="bg-white p-4 rounded-lg shadow-xl" style={{ width: "300px" }} onClick={(e) => e.stopPropagation()}>
<h2 className="text-xl font-bold text-center mb-2 text-gray-800">Koordinaten</h2>
<p className="text-center text-lg text-gray-600 font-mono mb-0">lat , lng</p>
<p className="text-center text-lg text-gray-600 font-mono mb-6">{coordinates}</p>
<div className="flex justify-center gap-4">
<button onClick={copyToClipboard} className="bg-blue-500 text-white px-6 py-2 rounded-lg shadow hover:bg-blue-600 transition-all">
Kopieren
</button>
<button onClick={onClose} className="bg-gray-300 text-gray-800 px-6 py-2 rounded-lg shadow hover:bg-gray-400 transition-all">
Schließen
</button>
</div>
</div>
</div>
);
};
export default CoordinatePopup;

View File

@@ -0,0 +1,86 @@
// components/useMapContextMenu.js
import { toast } from "react-toastify";
import { zoomIn, zoomOut, centerHere } from "../../utils/zoomAndCenterUtils";
// components/useMapContextMenu.js
const addItemsToMapContextMenu = (
map,
menuItemAdded,
setMenuItemAdded,
setShowCoordinatesModal,
setShowPoiModal,
setPopupCoordinates,
openPopupWithCoordinates // Hier wird die Funktion als Parameter hinzugefügt
) => {
const openPoiModal = (e) => {
setShowCoordinatesModal(false); // ✅ Jetzt verfügbar, weil als Parameter übergeben
setPopupCoordinates(e.latlng);
setShowPoiModal(true);
};
if (!menuItemAdded && map && map.contextmenu) {
map.contextmenu.addItem({
text: "Koordinaten anzeigen",
icon: "img/not_listed_location.png",
callback: openPopupWithCoordinates, // Aufruf des Popup-Callbacks
});
map.contextmenu.addItem({ separator: true });
map.contextmenu.addItem({
text: "Reinzoomen",
icon: "img/zoom_in.png",
callback: (e) => {
const currentZoom = map.getZoom();
const newZoom = Math.min(15, currentZoom + 3); // Stellt sicher, dass max. 15 erreicht wird
const zoomDifference = Math.abs(newZoom - currentZoom); // Anzahl der Zoom-Stufen
const duration = zoomDifference * 0.5; // Pro Stufe 0.5 Sekunden
map.flyTo(map.getCenter(), newZoom, {
animate: true,
duration: duration,
});
},
});
map.contextmenu.addItem({
text: "Rauszoomen",
icon: "img/zoom_out.png",
callback: () => {
const currentZoom = map.getZoom();
const newZoom = Math.max(6, currentZoom - 3); // Stellt sicher, dass min. 6 erreicht wird
const zoomDifference = Math.abs(newZoom - currentZoom); // Anzahl der Zoom-Stufen
const duration = zoomDifference * 0.5; // Pro Stufe 0.5 Sekunden
map.flyTo(map.getCenter(), newZoom, {
animate: true,
duration: duration,
});
},
});
map.contextmenu.addItem({
text: "Hier zentrieren",
icon: "img/center_focus.png",
callback: (e) => {
map.panTo(e.latlng);
},
});
setMenuItemAdded(true);
}
if (!menuItemAdded && map && map.contextmenu) {
const editMode = localStorage.getItem("editMode") === "true";
if (editMode) {
console.log("editMode localStorage:", localStorage.getItem("editMode"));
//console.log("editMode:", editMode);
map.contextmenu.addItem({
text: "POI hinzufügen",
icon: "/img/add_station.png",
callback: openPoiModal, // Jetzt mit Zugriff auf `setShowPoiModal`
});
}
}
};
export default addItemsToMapContextMenu;