// utils/contextMenuUtils.js import { BASE_URL } from "../config/urls"; import { store } from "../redux/store"; // Redux-Store importieren export function addContextMenuToMarker(marker) { marker.unbindContextMenu(); // Entferne das Kontextmenü, um Duplikate zu vermeiden const selectedDevice = store.getState().selectedDevice; // Redux-Wert abrufen const contextMenuItems = []; // ✅ Nur hinzufügen, wenn `selectedDevice` vorhanden ist if (marker?.options?.idDevice && marker?.options?.link) { contextMenuItems.push({ text: "Station öffnen (Tab)", icon: "/img/screen_new.png", callback: (e) => openInNewTab(e, marker), }); } // Falls weitere Kontextmenü-Optionen nötig sind, können sie hier hinzugefügt werden. marker.bindContextMenu({ contextmenu: true, contextmenuWidth: 140, contextmenuItems: contextMenuItems, }); } // Funktion zum Öffnen in einem neuen Tab export function openInNewTab(e, marker) { const baseUrl = BASE_URL; console.log("baseUrl:", baseUrl); if (marker && marker.options && marker.options.link) { window.open(baseUrl + marker.options.link, "_blank"); } else { console.error("Fehler: Marker hat keine gültige 'link' Eigenschaft"); } }