// utils/openInNewTab.js export function openInNewTab(e, target) { const url = new URL(window.location.origin); const originWithoutPort = `${url.protocol}//${url.hostname}`; // Protokoll und Hostname, ohne Port let link; // Prüfen, ob der Kontextmenü-Eintrag aufgerufen wird, ohne dass ein Marker oder Polyline direkt angesprochen wird if (!target) { // Verwende den in localStorage gespeicherten Link const lastElementType = localStorage.getItem("lastElementType"); if (lastElementType === "polyline") { link = localStorage.getItem("polylineLink"); } } if (target instanceof L.Marker && target.options.link) { link = `${originWithoutPort}/talas5/devices/${target.options.link}`; console.log("Link des Markers", link); } else if (target instanceof L.Polyline) { const idLD = target.options.idLD; console.log("idLD der Linie", idLD); if (idLD) { link = `${originWithoutPort}/talas5/devices/cpl.aspx?id=${idLD}`; } else { console.error("Keine gültige 'idLD' für die Linie gefunden."); return; } } else if (!link) { console.error("Fehler: Es wurde kein gültiger Link gefunden."); return; } // Öffne den Link in einem neuen Tab if (link) { window.open(link, "_blank"); } else { console.error("Fehler: Es wurde kein gültiger Link gefunden."); } }