fix: Duplizierte Kontextmenü-Einträge verhindert und Cleanup hinzugefügt
- Kontextmenü wird jetzt nur einmal hinzugefügt, wenn es noch nicht existiert. - Vor dem Hinzufügen wird geprüft, ob bereits Einträge existieren, um Duplikate zu vermeiden. - Kontextmenü wird entfernt, wenn außerhalb geklickt wird, um Speicherlecks zu verhindern. - Nutzung eines `Set()` für Menü-IDs, um doppelte Einträge sicher zu verhindern.
This commit is contained in:
@@ -1,31 +1,38 @@
|
||||
// contextMenuUtils.js
|
||||
// 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 (selectedDevice && marker.options?.idDevice) {
|
||||
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: [
|
||||
/* {
|
||||
text: "Station öffnen (Tab)",
|
||||
icon: "/img/screen_new.png",
|
||||
callback: (e) => openInNewTab(e, marker),
|
||||
},
|
||||
{
|
||||
text: "Station öffnen",
|
||||
icon: "/img/screen_same.png",
|
||||
callback: (e) => openInSameWindow(e, marker),
|
||||
}, */
|
||||
],
|
||||
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) {
|
||||
//console.log("Marker data:", baseUrl + marker.options.link);
|
||||
window.open(baseUrl + marker.options.link, "_blank");
|
||||
} else {
|
||||
console.error("Fehler: Marker hat keine gültige 'link' Eigenschaft");
|
||||
|
||||
Reference in New Issue
Block a user