diff --git a/hooks/layers/useGmaMarkersLayer.js b/hooks/layers/useGmaMarkersLayer.js index b32528063..9f53f5b74 100644 --- a/hooks/layers/useGmaMarkersLayer.js +++ b/hooks/layers/useGmaMarkersLayer.js @@ -1,6 +1,5 @@ import { useEffect } from "react"; import { addContextMenuToMarker } from "../../utils/addContextMenuToMarker"; -import { addItemsToMapContextMenu } from "../../components/useMapContextMenu"; // Importiere die Funktion const useGmaMarkersLayer = (map, markers, GisStationsMeasurements, GMA, oms, isVisible) => { const zoomIn = (map, latlng) => { @@ -8,16 +7,15 @@ const useGmaMarkersLayer = (map, markers, GisStationsMeasurements, GMA, oms, isV console.error("map is not defined in zoomIn"); return; } - + const currentZoom = map.getZoom(); - + if (currentZoom < 14) { map.flyTo(latlng, 14); localStorage.setItem("mapZoom", 14); localStorage.setItem("mapCenter", JSON.stringify(map.getCenter())); } }; - const zoomOut = (map) => { if (!map) { @@ -47,9 +45,6 @@ const useGmaMarkersLayer = (map, markers, GisStationsMeasurements, GMA, oms, isV localStorage.setItem("mapZoom", map.getZoom()); localStorage.setItem("mapCenter", JSON.stringify(map.getCenter())); }; - const protocol = window.location.protocol; // Holt das Protokoll (z.B. http oder https) - const hostname = window.location.hostname; // Holt den Hostnamen (z.B. 10.10.0.70) - const baseUrl = `${protocol}//${hostname}/talas5/devices/`; // Basis-URL zusammenstellen useEffect(() => { if (!map || !isVisible) return; @@ -100,6 +95,15 @@ const useGmaMarkersLayer = (map, markers, GisStationsMeasurements, GMA, oms, isV } ); + let currentMouseLatLng = null; + + const mouseMoveHandler = (event) => { + currentMouseLatLng = event.latlng; + }; + + // Mousemove-Listener hinzufügen, um die aktuellen Koordinaten zu speichern + map.on("mousemove", mouseMoveHandler); + marker.on("tooltipopen", (e) => { const tooltipElement = e.tooltip._contentNode; @@ -108,7 +112,6 @@ const useGmaMarkersLayer = (map, markers, GisStationsMeasurements, GMA, oms, isV event.preventDefault(); console.log("Rechtsklick auf Tooltip erkannt"); - // Kombiniere die Kontextmenü-Items // Kombiniere die Kontextmenü-Items const combinedContextMenuItems = [ { @@ -116,7 +119,7 @@ const useGmaMarkersLayer = (map, markers, GisStationsMeasurements, GMA, oms, isV icon: "/img/screen_new.png", callback: () => { if (marker.options.link) { - const fullUrl = `${baseUrl}${marker.options.link}`; + const fullUrl = `${marker.options.link}`; window.open(fullUrl, "_blank"); console.log("Link in neuem Tab geöffnet:", fullUrl); } else { @@ -125,21 +128,25 @@ const useGmaMarkersLayer = (map, markers, GisStationsMeasurements, GMA, oms, isV }, }, { separator: true }, - //Koordinaten anzeigen auf den gesamte Tooltip fläche ist ein Wert, deswegen ausgeblendet - /* { + { text: "Koordinaten anzeigen", icon: "/img/not_listed_location.png", callback: () => { - const latlng = marker.getLatLng(); // Hole die Koordinaten direkt vom Marker - alert("Breitengrad: " + latlng.lat.toFixed(5) + "\nLängengrad: " + latlng.lng.toFixed(5)); + if (currentMouseLatLng) { + alert( + `Breitengrad: ${currentMouseLatLng.lat.toFixed(5)}\nLängengrad: ${currentMouseLatLng.lng.toFixed(5)}` + ); + } else { + console.error("Keine gültigen Koordinaten erkannt."); + } }, - }, */ + }, { separator: true }, { text: "Reinzoomen", icon: "img/zoom_in.png", callback: () => { - const latlng = marker.getLatLng(); // Hole die Koordinaten direkt vom Marker + const latlng = marker.getLatLng(); zoomIn(map, latlng); }, }, @@ -152,7 +159,7 @@ const useGmaMarkersLayer = (map, markers, GisStationsMeasurements, GMA, oms, isV text: "Hier zentrieren", icon: "img/center_focus.png", callback: () => { - const latlng = marker.getLatLng(); // Hole die Koordinaten direkt vom Marker + const latlng = marker.getLatLng(); centerHere({ latlng }, map); }, }, @@ -212,6 +219,10 @@ const useGmaMarkersLayer = (map, markers, GisStationsMeasurements, GMA, oms, isV } }); + marker.on("tooltipclose", () => { + map.off("mousemove", mouseMoveHandler); + }); + addContextMenuToMarker(marker); GMA.addLayer(marker);