diff --git a/components/CoordinatePopup.js b/components/CoordinatePopup.js index e8785bb81..aa565d434 100644 --- a/components/CoordinatePopup.js +++ b/components/CoordinatePopup.js @@ -4,33 +4,56 @@ 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 (
lat , lng
{coordinates}