Files
nodeMap/redux/slices/mapLayersSlice.js
ISA be2da8414c git commit -m "refactor: Gerätelayer dynamisch über IdSystem initialisiert
BREAKING CHANGE: Sichtbarkeit der Gerätegruppen basiert nun auf 'system-<IdSystem>' statt auf Namen wie 'SMSFunkmodem'. Statische Layer-Konfiguration im Redux-Slice entfernt."
2025-06-02 09:00:49 +02:00

35 lines
1.0 KiB
JavaScript

// redux/slices/mapLayersSlice.js
import { createSlice } from "@reduxjs/toolkit";
const initialState = {};
const mapLayersSlice = createSlice({
name: "mapLayers",
initialState,
reducers: {
toggleLayer: (state, action) => {
const layer = action.payload;
if (state[layer] !== undefined) {
state[layer] = !state[layer]; // Toggle Sichtbarkeit
}
},
setLayerVisibility: (state, action) => {
const { layer, visibility } = action.payload;
if (state[layer] !== undefined) {
state[layer] = visibility;
}
},
setInitialLayers: (state, action) => {
const systems = action.payload; // Array of GisSystem
systems.forEach((system) => {
const key = `system-${system.IdSystem}`;
state[key] = true; // oder false, je nach Default
});
},
},
});
export const { toggleLayer, setLayerVisibility, setInitialLayers } = mapLayersSlice.actions;
export const selectMapLayersState = (state) => state.mapLayers || initialState;
export default mapLayersSlice.reducer;