Files
nodeMap/utils/openInNewTab.js
ISA 6fa4d86cd1 Version 1.0.11
fix: openInNewTab.js
2024-12-06 07:33:35 +01:00

41 lines
1.3 KiB
JavaScript

// 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
const BASE_URL = originWithoutPort;
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}`;
} 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.");
}
}