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:
18
utils/setupDevices.js
Normal file
18
utils/setupDevices.js
Normal file
@@ -0,0 +1,18 @@
|
||||
// utils/setupDevices.js
|
||||
import { setSelectedDevice, clearSelectedDevice } from "../redux/slices/selectedDeviceSlice";
|
||||
|
||||
export const setupDevices = async (map, deviceMarkers, dispatch) => {
|
||||
for (const marker of deviceMarkers) {
|
||||
marker.on("mouseover", function () {
|
||||
console.log("✅ Gerät ausgewählt:", marker);
|
||||
dispatch(setSelectedDevice(marker.options)); // Gerät in Redux speichern
|
||||
});
|
||||
|
||||
marker.on("mouseout", function () {
|
||||
console.log("❌ Gerät abgewählt");
|
||||
dispatch(clearSelectedDevice()); // Gerät aus Redux entfernen
|
||||
});
|
||||
|
||||
marker.addTo(map);
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user