forked from MapComplete/MapComplete
Add switch to disable all layers by default
This commit is contained in:
parent
5628e66dce
commit
de9691e723
4 changed files with 18 additions and 7 deletions
|
@ -68,6 +68,7 @@ export default class FeatureSwitchState extends OsmConnectionFeatureSwitches {
|
||||||
public readonly osmApiTileSize: UIEventSource<number>
|
public readonly osmApiTileSize: UIEventSource<number>
|
||||||
public readonly backgroundLayerId: UIEventSource<string>
|
public readonly backgroundLayerId: UIEventSource<string>
|
||||||
public readonly featureSwitchMorePrivacy: UIEventSource<boolean>
|
public readonly featureSwitchMorePrivacy: UIEventSource<boolean>
|
||||||
|
public readonly featureSwitchLayerDefault: UIEventSource<boolean>
|
||||||
|
|
||||||
public constructor(layoutToUse?: LayoutConfig) {
|
public constructor(layoutToUse?: LayoutConfig) {
|
||||||
super()
|
super()
|
||||||
|
@ -234,5 +235,9 @@ export default class FeatureSwitchState extends OsmConnectionFeatureSwitches {
|
||||||
layoutToUse?.defaultBackgroundId,
|
layoutToUse?.defaultBackgroundId,
|
||||||
"The id of the background layer to start with"
|
"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"
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import { UIEventSource } from "../UIEventSource"
|
import { Store, UIEventSource } from "../UIEventSource"
|
||||||
import { GlobalFilter } from "../../Models/GlobalFilter"
|
import { GlobalFilter } from "../../Models/GlobalFilter"
|
||||||
import FilteredLayer from "../../Models/FilteredLayer"
|
import FilteredLayer from "../../Models/FilteredLayer"
|
||||||
import LayerConfig from "../../Models/ThemeConfig/LayerConfig"
|
import LayerConfig from "../../Models/ThemeConfig/LayerConfig"
|
||||||
|
@ -32,15 +32,16 @@ export default class LayerState {
|
||||||
*
|
*
|
||||||
* @param osmConnection
|
* @param osmConnection
|
||||||
* @param layers
|
* @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<boolean>) {
|
||||||
this.osmConnection = osmConnection
|
this.osmConnection = osmConnection
|
||||||
const filteredLayers = new Map()
|
const filteredLayers = new Map()
|
||||||
for (const layer of layers) {
|
for (const layer of layers) {
|
||||||
filteredLayers.set(
|
filteredLayers.set(
|
||||||
layer.id,
|
layer.id,
|
||||||
FilteredLayer.initLinkedState(layer, context, this.osmConnection)
|
FilteredLayer.initLinkedState(layer, context, this.osmConnection, layersEnabledByDefault)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
this.filteredLayers = filteredLayers
|
this.filteredLayers = filteredLayers
|
||||||
|
|
|
@ -81,7 +81,8 @@ export default class FilteredLayer {
|
||||||
public static initLinkedState(
|
public static initLinkedState(
|
||||||
layer: LayerConfig,
|
layer: LayerConfig,
|
||||||
context: string,
|
context: string,
|
||||||
osmConnection: OsmConnection
|
osmConnection: OsmConnection,
|
||||||
|
enabledByDefault?: Store<boolean>
|
||||||
) {
|
) {
|
||||||
let isDisplayed: UIEventSource<boolean>
|
let isDisplayed: UIEventSource<boolean>
|
||||||
if (layer.syncSelection === "local") {
|
if (layer.syncSelection === "local") {
|
||||||
|
@ -102,9 +103,13 @@ export default class FilteredLayer {
|
||||||
layer
|
layer
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
|
let isShown = layer.shownByDefault
|
||||||
|
if(enabledByDefault !== undefined && enabledByDefault.data === false){
|
||||||
|
isShown = false
|
||||||
|
}
|
||||||
isDisplayed = QueryParameters.GetBooleanQueryParameter(
|
isDisplayed = QueryParameters.GetBooleanQueryParameter(
|
||||||
FilteredLayer.queryParameterKey(layer),
|
FilteredLayer.queryParameterKey(layer),
|
||||||
layer.shownByDefault,
|
isShown ,
|
||||||
"Whether or not layer " + layer.id + " is shown"
|
"Whether or not layer " + layer.id + " is shown"
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
@ -202,7 +202,7 @@ export default class ThemeViewState implements SpecialVisualizationState {
|
||||||
)
|
)
|
||||||
|
|
||||||
const self = this
|
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<string, { isDisplayed: UIEventSource<boolean> }>()
|
const overlayLayerStates = new Map<string, { isDisplayed: UIEventSource<boolean> }>()
|
||||||
|
|
Loading…
Add table
Reference in a new issue