Files
nodeMap/utils/contextMenuUtils.js

34 lines
998 B
JavaScript

// utils/contextMenuUtils.js
import { BASE_URL } from "../config/paths";
import { store } from "../redux/store"; // Redux-Store importieren
import { openInNewTab } from "./openInNewTab";
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({
separator: true,
});
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,
});
}