From 65109cc95338045e42523db438a8f9f1b9d80b2d Mon Sep 17 00:00:00 2001 From: ISA Date: Mon, 30 Dec 2024 12:19:30 +0100 Subject: [PATCH] Koordinaten kopieren --- components/useMapContextMenu.js | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/components/useMapContextMenu.js b/components/useMapContextMenu.js index 24133ae82..06cbf0c62 100644 --- a/components/useMapContextMenu.js +++ b/components/useMapContextMenu.js @@ -13,9 +13,22 @@ const centerHereCallback = (e, map) => { centerHere(e, map); }; +// Hilfsfunktion zur Umwandlung in das DMS-Format +const toDMS = (decimal, isLat) => { + const direction = decimal >= 0 ? (isLat ? "N" : "E") : isLat ? "S" : "W"; + const absDecimal = Math.abs(decimal); + const degrees = Math.floor(absDecimal); + const minutesDecimal = (absDecimal - degrees) * 60; + const minutes = Math.floor(minutesDecimal); + const seconds = ((minutesDecimal - minutes) * 60).toFixed(1); + return `${degrees}°${minutes}'${seconds}"${direction}`; +}; + // Funktion zum Anzeigen und Kopieren der Koordinaten const showCoordinates = (e) => { - const coordinates = `Breitengrad: ${e.latlng.lat.toFixed(5)}, Längengrad: ${e.latlng.lng.toFixed(5)}`; + const latDMS = toDMS(e.latlng.lat, true); + const lngDMS = toDMS(e.latlng.lng, false); + const coordinates = `${latDMS} ${lngDMS}`; // Überprüfen, ob das Clipboard-API unterstützt wird if (navigator.clipboard && navigator.clipboard.writeText) { @@ -109,7 +122,10 @@ export const addItemsToMapContextMenu = (map, menuItemAdded, setMenuItemAdded, h map.contextmenu.removeAllItems(); // Koordinaten dynamisch anzeigen - const coordinates = `Lat: ${e.latlng.lat.toFixed(5)}, Lng: ${e.latlng.lng.toFixed(5)}`; + const latDMS = toDMS(e.latlng.lat, true); + const lngDMS = toDMS(e.latlng.lng, false); + const coordinates = `${latDMS} ${lngDMS}`; + map.contextmenu.addItem({ text: coordinates, icon: "img/not_listed_location.png",