diff --git a/components/MapComponent.js b/components/MapComponent.js index 7b891e9ce..4ebaa2bfa 100644 --- a/components/MapComponent.js +++ b/components/MapComponent.js @@ -48,6 +48,7 @@ const plusRoundIcon = L.icon({ }); const MapComponent = ({ locations, onLocationUpdate, lineCoordinates }) => { + const [menuItemAdded, setMenuItemAdded] = useState(false); const linePositions = lineCoordinates || [ [52.505, 8], [52, 8.5], @@ -1135,28 +1136,31 @@ const MapComponent = ({ locations, onLocationUpdate, lineCoordinates }) => { }).addTo(map); } }, [map]); */ - const addItemsToMapContextMenu = () => { - console.log("contextMenuItems hasRights:", hasRights); - map.contextmenu.addItem({ - text: "POI hinzufügen", - icon: "img/add_station.png", - className: "background-red", - callback: (event) => addStationCallback(event, hasRights), - }); + const addItemsToMapContextMenu = () => { + if (!menuItemAdded) { + console.log("contextMenuItems hasRights:", hasRights); + + map.contextmenu.addItem({ + text: "POI hinzufügen", + icon: "img/add_station.png", + className: "background-red", + callback: (event) => addStationCallback(event, hasRights), + }); + + setMenuItemAdded(true); // Menüpunkt wurde hinzugefült, Zustand aktualisieren + } }; - //-------------------------------------------------- + useEffect(() => { - if (map && poiLayerRef.current && isPoiTypLoaded) { + if (map && poiLayerRef.current && isPoiTypLoaded && !menuItemAdded) { addItemsToMapContextMenu(); } }, [ map, - locations, - onLocationUpdate, - poiReadTrigger, + poiLayerRef, isPoiTypLoaded, - userRights, + menuItemAdded, // Hinzufügen zu den Abhängigkeiten, um den Effekt korrekt zu steuern ]); //------------------------------------------