From de9691e72392e97c4c39a6430e066417595e1799 Mon Sep 17 00:00:00 2001 From: Pieter Vander Vennet Date: Thu, 27 Jun 2024 01:57:32 +0200 Subject: [PATCH] Add switch to disable all layers by default --- src/Logic/State/FeatureSwitchState.ts | 5 +++++ src/Logic/State/LayerState.ts | 9 +++++---- src/Models/FilteredLayer.ts | 9 +++++++-- src/Models/ThemeViewState.ts | 2 +- 4 files changed, 18 insertions(+), 7 deletions(-) diff --git a/src/Logic/State/FeatureSwitchState.ts b/src/Logic/State/FeatureSwitchState.ts index 6fbd1ad3b..b4030ce1f 100644 --- a/src/Logic/State/FeatureSwitchState.ts +++ b/src/Logic/State/FeatureSwitchState.ts @@ -68,6 +68,7 @@ export default class FeatureSwitchState extends OsmConnectionFeatureSwitches { public readonly osmApiTileSize: UIEventSource public readonly backgroundLayerId: UIEventSource public readonly featureSwitchMorePrivacy: UIEventSource + public readonly featureSwitchLayerDefault: UIEventSource public constructor(layoutToUse?: LayoutConfig) { super() @@ -234,5 +235,9 @@ export default class FeatureSwitchState extends OsmConnectionFeatureSwitches { layoutToUse?.defaultBackgroundId, "The id of the background layer to start with" ) + + this.featureSwitchLayerDefault = QueryParameters.GetBooleanQueryParameter("fs-layers-enabled",true, + "If set to false, all layers will be disabled - except the explicitly enabled layers" + ) } } diff --git a/src/Logic/State/LayerState.ts b/src/Logic/State/LayerState.ts index f8fb30761..d90b2d9ac 100644 --- a/src/Logic/State/LayerState.ts +++ b/src/Logic/State/LayerState.ts @@ -1,4 +1,4 @@ -import { UIEventSource } from "../UIEventSource" +import { Store, UIEventSource } from "../UIEventSource" import { GlobalFilter } from "../../Models/GlobalFilter" import FilteredLayer from "../../Models/FilteredLayer" import LayerConfig from "../../Models/ThemeConfig/LayerConfig" @@ -32,15 +32,16 @@ export default class LayerState { * * @param osmConnection * @param layers - * @param context: the context, probably the name of the theme. Used to disambiguate the upstream user preference + * @param context + * @param layersEnabledByDefault */ - constructor(osmConnection: OsmConnection, layers: LayerConfig[], context: string) { + constructor(osmConnection: OsmConnection, layers: LayerConfig[], context: string, layersEnabledByDefault: Store) { this.osmConnection = osmConnection const filteredLayers = new Map() for (const layer of layers) { filteredLayers.set( layer.id, - FilteredLayer.initLinkedState(layer, context, this.osmConnection) + FilteredLayer.initLinkedState(layer, context, this.osmConnection, layersEnabledByDefault) ) } this.filteredLayers = filteredLayers diff --git a/src/Models/FilteredLayer.ts b/src/Models/FilteredLayer.ts index 8732a9a73..a9dccff3e 100644 --- a/src/Models/FilteredLayer.ts +++ b/src/Models/FilteredLayer.ts @@ -81,7 +81,8 @@ export default class FilteredLayer { public static initLinkedState( layer: LayerConfig, context: string, - osmConnection: OsmConnection + osmConnection: OsmConnection, + enabledByDefault?: Store ) { let isDisplayed: UIEventSource if (layer.syncSelection === "local") { @@ -102,9 +103,13 @@ export default class FilteredLayer { layer ) } else { + let isShown = layer.shownByDefault + if(enabledByDefault !== undefined && enabledByDefault.data === false){ + isShown = false + } isDisplayed = QueryParameters.GetBooleanQueryParameter( FilteredLayer.queryParameterKey(layer), - layer.shownByDefault, + isShown , "Whether or not layer " + layer.id + " is shown" ) } diff --git a/src/Models/ThemeViewState.ts b/src/Models/ThemeViewState.ts index 62e0b7974..e34a4f439 100644 --- a/src/Models/ThemeViewState.ts +++ b/src/Models/ThemeViewState.ts @@ -202,7 +202,7 @@ export default class ThemeViewState implements SpecialVisualizationState { ) const self = this - this.layerState = new LayerState(this.osmConnection, layout.layers, layout.id) + this.layerState = new LayerState(this.osmConnection, layout.layers, layout.id, this.featureSwitches.featureSwitchLayerDefault) { const overlayLayerStates = new Map }>()