feat: implement map-specific localStorage and TALAS-Kabelstrecken dependency logic
- Add map-specific localStorage keys using URL parameters (m=mapId, u=userId)
- Implement kartenspezifische Sichtbarkeitseinstellungen per Map/User
- Fix localStorage priority over GisSystemStatic Allow values to preserve user settings
- Add bidirectional TALAS ↔ Kabelstrecken dependency logic:
* Kabelstrecken aktiviert → TALAS automatisch aktiviert
* TALAS deaktiviert → Kabelstrecken automatisch deaktiviert
- Update mapLayersSlice.js to respect existing localStorage values over system defaults
- Modify MapComponent.js to load map-specific visibility settings on mount
- Update MapLayersControlPanel.js with kartenspezifische localStorage handling
- Fix useDynamicDeviceLayers.js visibility logic (corrected boolean conditions)
- Update useAreaMarkersLayer.js for map-specific localStorage keys
BREAKING CHANGES:
- localStorage structure changed from "mapLayersVisibility" to "mapLayersVisibility_m{mapId}_u{userId}"
- User visibility preferences now have priority over GisSystemStatic Allow values
- TALAS and Kabelstrecken are now logically linked (dependency relationship)
This resolves issues with:
- Map switching losing visibility settings
- Browser reload overriding user preferences with system defaults
- Missing logical connection between TALAS stations and their cable routes
This commit is contained in:
@@ -57,12 +57,21 @@ function MapLayersControlPanel() {
|
||||
console.log("📢 Event 'polylineVisibilityChanged' dispatched");
|
||||
}, 100);
|
||||
|
||||
// Wenn Kabelstrecken aktiviert wird, aktiviere automatisch auch TALAS (IdSystem 1)
|
||||
if (checked) {
|
||||
dispatch(setLayerVisibility({ layer: "TALAS", visibility: true }));
|
||||
localStorage.setItem(
|
||||
"mapLayersVisibility",
|
||||
JSON.stringify({ ...mapLayersVisibility, TALAS: true })
|
||||
);
|
||||
const talasKey = "system-1"; // TALAS hat IdSystem 1
|
||||
dispatch(setLayerVisibility({ layer: talasKey, visibility: true }));
|
||||
|
||||
// Kartenspezifischer localStorage-Key verwenden
|
||||
const mapId = localStorage.getItem("currentMapId");
|
||||
const userId = localStorage.getItem("currentUserId");
|
||||
const mapStorageKey =
|
||||
mapId && userId ? `mapLayersVisibility_m${mapId}_u${userId}` : "mapLayersVisibility";
|
||||
|
||||
const updatedVisibility = { ...mapLayersVisibility, [talasKey]: true };
|
||||
localStorage.setItem(mapStorageKey, JSON.stringify(updatedVisibility));
|
||||
|
||||
console.log("🔗 Kabelstrecken aktiviert → TALAS automatisch aktiviert");
|
||||
}
|
||||
};
|
||||
|
||||
@@ -108,8 +117,15 @@ function MapLayersControlPanel() {
|
||||
}, 200);
|
||||
}
|
||||
|
||||
const storedMapLayersVisibility = localStorage.getItem("mapLayersVisibility");
|
||||
console.log("📦 MapLayers localStorage value:", storedMapLayersVisibility);
|
||||
// Kartenspezifischer localStorage-Key verwenden
|
||||
const mapId = localStorage.getItem("currentMapId");
|
||||
const userId = localStorage.getItem("currentUserId");
|
||||
const mapStorageKey =
|
||||
mapId && userId ? `mapLayersVisibility_m${mapId}_u${userId}` : "mapLayersVisibility";
|
||||
|
||||
const storedMapLayersVisibility = localStorage.getItem(mapStorageKey);
|
||||
console.log(`📦 MapLayers localStorage value for ${mapStorageKey}:`, storedMapLayersVisibility);
|
||||
|
||||
if (storedMapLayersVisibility) {
|
||||
const parsedVisibility = JSON.parse(storedMapLayersVisibility);
|
||||
Object.keys(parsedVisibility).forEach(key => {
|
||||
@@ -121,15 +137,16 @@ function MapLayersControlPanel() {
|
||||
if (Array.isArray(GisSystemStatic)) {
|
||||
const initialVisibility = {};
|
||||
GisSystemStatic.forEach(system => {
|
||||
const systemKey = `system-${system.IdSystem}`;
|
||||
const visibility = system.Allow === 1;
|
||||
initialVisibility[system.SystemName] = visibility;
|
||||
dispatch(setLayerVisibility({ layer: system.SystemName, visibility }));
|
||||
initialVisibility[systemKey] = visibility;
|
||||
dispatch(setLayerVisibility({ layer: systemKey, visibility }));
|
||||
console.log(
|
||||
`🎯 Setting ${system.SystemName} visibility to ${visibility} (Allow=${system.Allow})`
|
||||
`🎯 Setting ${systemKey} (${system.Name}) visibility to ${visibility} (Allow=${system.Allow})`
|
||||
);
|
||||
});
|
||||
localStorage.setItem("mapLayersVisibility", JSON.stringify(initialVisibility));
|
||||
console.log("💾 Saved initial mapLayersVisibility to localStorage:", initialVisibility);
|
||||
localStorage.setItem(mapStorageKey, JSON.stringify(initialVisibility));
|
||||
console.log(`💾 Saved initial mapLayersVisibility to ${mapStorageKey}:`, initialVisibility);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -197,10 +214,32 @@ function MapLayersControlPanel() {
|
||||
const { checked } = event.target;
|
||||
|
||||
dispatch(setLayerVisibility({ layer: key, visibility: checked }));
|
||||
localStorage.setItem(
|
||||
"mapLayersVisibility",
|
||||
JSON.stringify({ ...mapLayersVisibility, [key]: checked })
|
||||
);
|
||||
|
||||
// Kartenspezifischer localStorage-Key verwenden
|
||||
const mapId = localStorage.getItem("currentMapId");
|
||||
const userId = localStorage.getItem("currentUserId");
|
||||
const mapStorageKey =
|
||||
mapId && userId ? `mapLayersVisibility_m${mapId}_u${userId}` : "mapLayersVisibility";
|
||||
|
||||
localStorage.setItem(mapStorageKey, JSON.stringify({ ...mapLayersVisibility, [key]: checked }));
|
||||
|
||||
// Wenn TALAS (system-1) deaktiviert wird, deaktiviere automatisch auch Kabelstrecken
|
||||
if (key === "system-1" && !checked) {
|
||||
console.log("🔗 TALAS deaktiviert → Kabelstrecken automatisch deaktiviert");
|
||||
|
||||
// Kabelstrecken deaktivieren
|
||||
setKabelstreckenVisible(false);
|
||||
localStorage.setItem("kabelstreckenVisible", "false");
|
||||
localStorage.setItem("polylineVisible", "false");
|
||||
dispatch(setPolylineVisible(false));
|
||||
|
||||
// Event für Kabelstrecken auslösen
|
||||
setTimeout(() => {
|
||||
const polylineEvent = new Event("polylineVisibilityChanged");
|
||||
window.dispatchEvent(polylineEvent);
|
||||
console.log("📢 Event 'polylineVisibilityChanged' dispatched (auto-deactivated)");
|
||||
}, 50);
|
||||
}
|
||||
|
||||
setTimeout(() => {
|
||||
const event = new Event("visibilityChanged");
|
||||
|
||||
Reference in New Issue
Block a user