Files
nodeMap/components/contextmenu/useMapContextMenu.js
ISA ec31b36b3d feat: Healthcheck um Webservices, API-Routen und .env-Prüfungen erweitert
- Externe Webservices von TALAS V5 integriert und geprüft (Statuscode + Antwortstruktur)
- Eigene API-Endpunkte wie /api/talas_v5_DB/getDevices hinzugefügt und validiert
- Prüfung von NEXT_PUBLIC_USE_MOCKS zur Vermeidung von Mockdaten in Produktion
- Validierung der Umgebungsvariablen wie DB_HOST, DB_NAME und NODE_ENV ergänzt
- Response-Status 200 bei vollständigem Erfolg, 207 bei Teilfehlern
- Verbesserung der JSON-Antwortstruktur zur einfacheren Analyse
2025-06-05 15:23:59 +02:00

88 lines
2.7 KiB
JavaScript

// components/contextmenu/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) {
if (process.env.NEXT_PUBLIC_DEBUG_LOG === "true") {
console.log("editMode localStorage:", localStorage.getItem("editMode"));
}
map.contextmenu.addItem({
text: "POI hinzufügen",
icon: "/img/add_station.png",
callback: openPoiModal, // Jetzt mit Zugriff auf `setShowPoiModal`
});
}
}
};
export default addItemsToMapContextMenu;