Files
nodeMap/utils/contextMenuUtils.js
ISA 771254db7e PS C:\Users\isa.LTW\Desktop\02.06.2025\NodeMap\02.06.2025 NodeMap> git push work tags
error: src refspec tags does not match any
error: failed to push some refs to 'http://10.10.0.12:3000/ISA/nodeMap'
PS C:\Users\isa.LTW\Desktop\02.06.2025\NodeMap\02.06.2025 NodeMap>
2025-06-02 11:15:34 +02:00

41 lines
1.2 KiB
JavaScript

// 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");
}
}