fix: useEffect nur einmal ausführen "POI hinzufügen" war manchmal zweimal oder mehr vorhanden im Kontextmenü
This commit is contained in:
@@ -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,7 +1136,9 @@ const MapComponent = ({ locations, onLocationUpdate, lineCoordinates }) => {
|
||||
}).addTo(map);
|
||||
}
|
||||
}, [map]); */
|
||||
|
||||
const addItemsToMapContextMenu = () => {
|
||||
if (!menuItemAdded) {
|
||||
console.log("contextMenuItems hasRights:", hasRights);
|
||||
|
||||
map.contextmenu.addItem({
|
||||
@@ -1144,19 +1147,20 @@ const MapComponent = ({ locations, onLocationUpdate, lineCoordinates }) => {
|
||||
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
|
||||
]);
|
||||
//------------------------------------------
|
||||
|
||||
|
||||
Reference in New Issue
Block a user