forked from MapComplete/MapComplete
		
	Add feature switch to disable the cache, partial fix to make GRB theme workable again
This commit is contained in:
		
							parent
							
								
									2e7703c8ec
								
							
						
					
					
						commit
						7b95303e76
					
				
					 8 changed files with 47 additions and 31 deletions
				
			
		| 
						 | 
					@ -787,5 +787,6 @@
 | 
				
			||||||
  },
 | 
					  },
 | 
				
			||||||
  "overpassMaxZoom": 15,
 | 
					  "overpassMaxZoom": 15,
 | 
				
			||||||
  "osmApiTileSize": 17,
 | 
					  "osmApiTileSize": 17,
 | 
				
			||||||
  "widenFactor": 2
 | 
					  "widenFactor": 2,
 | 
				
			||||||
 | 
					  "enableCache": false
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -112,7 +112,7 @@ export default class SelectedElementTagsUpdater {
 | 
				
			||||||
    private invalidateCache(s: Feature) {
 | 
					    private invalidateCache(s: Feature) {
 | 
				
			||||||
        const state = this.state
 | 
					        const state = this.state
 | 
				
			||||||
        const wasPartOfLayer = state.layout.getMatchingLayer(s.properties)
 | 
					        const wasPartOfLayer = state.layout.getMatchingLayer(s.properties)
 | 
				
			||||||
        state.toCacheSavers.get(wasPartOfLayer.id).invalidateCacheAround(BBox.get(s))
 | 
					        state.toCacheSavers?.get(wasPartOfLayer.id)?.invalidateCacheAround(BBox.get(s))
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    private installCallback() {
 | 
					    private installCallback() {
 | 
				
			||||||
        const state = this.state
 | 
					        const state = this.state
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -75,14 +75,7 @@ export default class ChangeGeometryApplicator implements FeatureSource {
 | 
				
			||||||
                newFeatures.push(feature)
 | 
					                newFeatures.push(feature)
 | 
				
			||||||
                continue
 | 
					                continue
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
            console.log(
 | 
					
 | 
				
			||||||
                "Applying a geometry change onto:",
 | 
					 | 
				
			||||||
                feature,
 | 
					 | 
				
			||||||
                "The change is:",
 | 
					 | 
				
			||||||
                change,
 | 
					 | 
				
			||||||
                "which becomes:",
 | 
					 | 
				
			||||||
                copy
 | 
					 | 
				
			||||||
            )
 | 
					 | 
				
			||||||
            newFeatures.push(copy)
 | 
					            newFeatures.push(copy)
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        this.features.setData(newFeatures)
 | 
					        this.features.setData(newFeatures)
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -27,6 +27,7 @@ export default class LayoutSource extends FeatureSourceMerger {
 | 
				
			||||||
    private readonly supportsForceDownload: UpdatableFeatureSource[]
 | 
					    private readonly supportsForceDownload: UpdatableFeatureSource[]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public static readonly fromCacheZoomLevel = 15
 | 
					    public static readonly fromCacheZoomLevel = 15
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    constructor(
 | 
					    constructor(
 | 
				
			||||||
        layers: LayerConfig[],
 | 
					        layers: LayerConfig[],
 | 
				
			||||||
        featureSwitches: FeatureSwitchState,
 | 
					        featureSwitches: FeatureSwitchState,
 | 
				
			||||||
| 
						 | 
					@ -45,20 +46,22 @@ export default class LayoutSource extends FeatureSourceMerger {
 | 
				
			||||||
        const geojsonlayers = layers.filter((layer) => layer.source.geojsonSource !== undefined)
 | 
					        const geojsonlayers = layers.filter((layer) => layer.source.geojsonSource !== undefined)
 | 
				
			||||||
        const osmLayers = layers.filter((layer) => layer.source.geojsonSource === undefined)
 | 
					        const osmLayers = layers.filter((layer) => layer.source.geojsonSource === undefined)
 | 
				
			||||||
        const fromCache = new Map<string, LocalStorageFeatureSource>()
 | 
					        const fromCache = new Map<string, LocalStorageFeatureSource>()
 | 
				
			||||||
        for (const layer of osmLayers) {
 | 
					        if (featureSwitches.featureSwitchCache.data) {
 | 
				
			||||||
            const src = new LocalStorageFeatureSource(
 | 
					            for (const layer of osmLayers) {
 | 
				
			||||||
                backend,
 | 
					                const src = new LocalStorageFeatureSource(
 | 
				
			||||||
                layer,
 | 
					                    backend,
 | 
				
			||||||
                LayoutSource.fromCacheZoomLevel,
 | 
					                    layer,
 | 
				
			||||||
                mapProperties,
 | 
					                    LayoutSource.fromCacheZoomLevel,
 | 
				
			||||||
                {
 | 
					                    mapProperties,
 | 
				
			||||||
                    isActive: isDisplayed(layer.id),
 | 
					                    {
 | 
				
			||||||
                    maxAge: layer.maxAgeOfCache,
 | 
					                        isActive: isDisplayed(layer.id),
 | 
				
			||||||
                }
 | 
					                        maxAge: layer.maxAgeOfCache
 | 
				
			||||||
            )
 | 
					                    }
 | 
				
			||||||
            fromCache.set(layer.id, src)
 | 
					                )
 | 
				
			||||||
        }
 | 
					                fromCache.set(layer.id, src)
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
        const mvtSources: UpdatableFeatureSource[] = osmLayers
 | 
					        const mvtSources: UpdatableFeatureSource[] = osmLayers
 | 
				
			||||||
            .filter((f) => mvtAvailableLayers.has(f.id))
 | 
					            .filter((f) => mvtAvailableLayers.has(f.id))
 | 
				
			||||||
            .map((l) => LayoutSource.setupMvtSource(l, mapProperties, isDisplayed(l.id)))
 | 
					            .map((l) => LayoutSource.setupMvtSource(l, mapProperties, isDisplayed(l.id)))
 | 
				
			||||||
| 
						 | 
					@ -104,7 +107,6 @@ export default class LayoutSource extends FeatureSourceMerger {
 | 
				
			||||||
        super(...geojsonSources, ...Array.from(fromCache.values()), ...mvtSources, ...nonMvtSources)
 | 
					        super(...geojsonSources, ...Array.from(fromCache.values()), ...mvtSources, ...nonMvtSources)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        this.isLoading = isLoading
 | 
					        this.isLoading = isLoading
 | 
				
			||||||
        this.fromCache = fromCache
 | 
					 | 
				
			||||||
        supportsForceDownload.push(...geojsonSources)
 | 
					        supportsForceDownload.push(...geojsonSources)
 | 
				
			||||||
        supportsForceDownload.push(...mvtSources) // Non-mvt sources are handled by overpass
 | 
					        supportsForceDownload.push(...mvtSources) // Non-mvt sources are handled by overpass
 | 
				
			||||||
        this.supportsForceDownload = supportsForceDownload
 | 
					        this.supportsForceDownload = supportsForceDownload
 | 
				
			||||||
| 
						 | 
					@ -168,7 +170,7 @@ export default class LayoutSource extends FeatureSourceMerger {
 | 
				
			||||||
            backend,
 | 
					            backend,
 | 
				
			||||||
            isActive,
 | 
					            isActive,
 | 
				
			||||||
            patchRelations: true,
 | 
					            patchRelations: true,
 | 
				
			||||||
            fullNodeDatabase,
 | 
					            fullNodeDatabase
 | 
				
			||||||
        })
 | 
					        })
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -200,11 +202,11 @@ export default class LayoutSource extends FeatureSourceMerger {
 | 
				
			||||||
                widenFactor: featureSwitches.layoutToUse.widenFactor,
 | 
					                widenFactor: featureSwitches.layoutToUse.widenFactor,
 | 
				
			||||||
                overpassUrl: featureSwitches.overpassUrl,
 | 
					                overpassUrl: featureSwitches.overpassUrl,
 | 
				
			||||||
                overpassTimeout: featureSwitches.overpassTimeout,
 | 
					                overpassTimeout: featureSwitches.overpassTimeout,
 | 
				
			||||||
                overpassMaxZoom: featureSwitches.overpassMaxZoom,
 | 
					                overpassMaxZoom: featureSwitches.overpassMaxZoom
 | 
				
			||||||
            },
 | 
					            },
 | 
				
			||||||
            {
 | 
					            {
 | 
				
			||||||
                padToTiles: zoom.map((zoom) => Math.min(15, zoom + 1)),
 | 
					                padToTiles: zoom.map((zoom) => Math.min(15, zoom + 1)),
 | 
				
			||||||
                isActive,
 | 
					                isActive
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
        )
 | 
					        )
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -57,6 +57,8 @@ export default class FeatureSwitchState extends OsmConnectionFeatureSwitches {
 | 
				
			||||||
    public readonly featureSwitchBackToThemeOverview: UIEventSource<boolean>
 | 
					    public readonly featureSwitchBackToThemeOverview: UIEventSource<boolean>
 | 
				
			||||||
    public readonly featureSwitchShareScreen: UIEventSource<boolean>
 | 
					    public readonly featureSwitchShareScreen: UIEventSource<boolean>
 | 
				
			||||||
    public readonly featureSwitchGeolocation: UIEventSource<boolean>
 | 
					    public readonly featureSwitchGeolocation: UIEventSource<boolean>
 | 
				
			||||||
 | 
					    public readonly featureSwitchCache: UIEventSource<boolean>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public readonly featureSwitchIsTesting: UIEventSource<boolean>
 | 
					    public readonly featureSwitchIsTesting: UIEventSource<boolean>
 | 
				
			||||||
    public readonly featureSwitchIsDebugging: UIEventSource<boolean>
 | 
					    public readonly featureSwitchIsDebugging: UIEventSource<boolean>
 | 
				
			||||||
    public readonly featureSwitchShowAllQuestions: UIEventSource<boolean>
 | 
					    public readonly featureSwitchShowAllQuestions: UIEventSource<boolean>
 | 
				
			||||||
| 
						 | 
					@ -176,6 +178,13 @@ export default class FeatureSwitchState extends OsmConnectionFeatureSwitches {
 | 
				
			||||||
            "Enable the export as GeoJSON and CSV button"
 | 
					            "Enable the export as GeoJSON and CSV button"
 | 
				
			||||||
        )
 | 
					        )
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        this.featureSwitchCache = FeatureSwitchUtils.initSwitch(
 | 
				
			||||||
 | 
					            "fs-cache",
 | 
				
			||||||
 | 
					            layoutToUse?.enableCache ?? true,
 | 
				
			||||||
 | 
					            "Enable/disable caching from localStorage"
 | 
				
			||||||
 | 
					        )
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        let testingDefaultValue = false
 | 
					        let testingDefaultValue = false
 | 
				
			||||||
        if (
 | 
					        if (
 | 
				
			||||||
            !Utils.runningFromConsole &&
 | 
					            !Utils.runningFromConsole &&
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -450,4 +450,14 @@ export interface LayoutConfigJson {
 | 
				
			||||||
     * iftrue: Do not write 'change_within_x_m' and do not indicate that this was done by survey
 | 
					     * iftrue: Do not write 'change_within_x_m' and do not indicate that this was done by survey
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
    enableMorePrivacy: boolean
 | 
					    enableMorePrivacy: boolean
 | 
				
			||||||
 | 
					    /**
 | 
				
			||||||
 | 
					     * question: Should this theme have the cache enabled?
 | 
				
			||||||
 | 
					     *
 | 
				
			||||||
 | 
					     * Should only be dissabled in highly specific cases, such as the GRB-theme
 | 
				
			||||||
 | 
					     *
 | 
				
			||||||
 | 
					     * ifunset: Cache is enabled
 | 
				
			||||||
 | 
					     * iffalse: Do not cache data
 | 
				
			||||||
 | 
					     * group: hidden
 | 
				
			||||||
 | 
					     */
 | 
				
			||||||
 | 
					    enableCache?: true | boolean
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -81,6 +81,7 @@ export default class LayoutConfig implements LayoutInformation {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    private readonly layersDict: Map<string, LayerConfig>
 | 
					    private readonly layersDict: Map<string, LayerConfig>
 | 
				
			||||||
    private readonly source: LayoutConfigJson
 | 
					    private readonly source: LayoutConfigJson
 | 
				
			||||||
 | 
					    public readonly enableCache: boolean
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    constructor(
 | 
					    constructor(
 | 
				
			||||||
        json: LayoutConfigJson,
 | 
					        json: LayoutConfigJson,
 | 
				
			||||||
| 
						 | 
					@ -98,6 +99,7 @@ export default class LayoutConfig implements LayoutInformation {
 | 
				
			||||||
        this.id = json.id
 | 
					        this.id = json.id
 | 
				
			||||||
        this.definedAtUrl = options?.definedAtUrl
 | 
					        this.definedAtUrl = options?.definedAtUrl
 | 
				
			||||||
        this.definitionRaw = options?.definitionRaw
 | 
					        this.definitionRaw = options?.definitionRaw
 | 
				
			||||||
 | 
					        this.enableCache = json.enableCache ?? true
 | 
				
			||||||
        if (official) {
 | 
					        if (official) {
 | 
				
			||||||
            if (json.id.toLowerCase() !== json.id) {
 | 
					            if (json.id.toLowerCase() !== json.id) {
 | 
				
			||||||
                throw "The id of a theme should be lowercase: " + json.id
 | 
					                throw "The id of a theme should be lowercase: " + json.id
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -204,7 +204,6 @@ export default class ThemeViewState implements SpecialVisualizationState {
 | 
				
			||||||
            this.osmConnection.isLoggedIn
 | 
					            this.osmConnection.isLoggedIn
 | 
				
			||||||
        )
 | 
					        )
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        const self = this
 | 
					 | 
				
			||||||
        this.layerState = new LayerState(
 | 
					        this.layerState = new LayerState(
 | 
				
			||||||
            this.osmConnection,
 | 
					            this.osmConnection,
 | 
				
			||||||
            layout.layers,
 | 
					            layout.layers,
 | 
				
			||||||
| 
						 | 
					@ -241,7 +240,7 @@ export default class ThemeViewState implements SpecialVisualizationState {
 | 
				
			||||||
                this.featureSwitches,
 | 
					                this.featureSwitches,
 | 
				
			||||||
                this.mapProperties,
 | 
					                this.mapProperties,
 | 
				
			||||||
                this.osmConnection.Backend(),
 | 
					                this.osmConnection.Backend(),
 | 
				
			||||||
                (id) => self.layerState.filteredLayers.get(id).isDisplayed,
 | 
					                (id) => this.layerState.filteredLayers.get(id).isDisplayed,
 | 
				
			||||||
                mvtAvailableLayers,
 | 
					                mvtAvailableLayers,
 | 
				
			||||||
                this.fullNodeDatabase
 | 
					                this.fullNodeDatabase
 | 
				
			||||||
            )
 | 
					            )
 | 
				
			||||||
| 
						 | 
					@ -316,7 +315,7 @@ export default class ThemeViewState implements SpecialVisualizationState {
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
            const floors = new Set<string>()
 | 
					            const floors = new Set<string>()
 | 
				
			||||||
            for (const feature of features) {
 | 
					            for (const feature of features) {
 | 
				
			||||||
                let level = feature.properties["_level"]
 | 
					                const level = feature.properties["_level"]
 | 
				
			||||||
                if (level) {
 | 
					                if (level) {
 | 
				
			||||||
                    const levels = level.split(";")
 | 
					                    const levels = level.split(";")
 | 
				
			||||||
                    for (const l of levels) {
 | 
					                    for (const l of levels) {
 | 
				
			||||||
| 
						 | 
					@ -379,7 +378,7 @@ export default class ThemeViewState implements SpecialVisualizationState {
 | 
				
			||||||
        this.featureSummary = this.setupSummaryLayer(
 | 
					        this.featureSummary = this.setupSummaryLayer(
 | 
				
			||||||
            new LayerConfig(<LayerConfigJson>summaryLayer, "summaryLayer", true)
 | 
					            new LayerConfig(<LayerConfigJson>summaryLayer, "summaryLayer", true)
 | 
				
			||||||
        )
 | 
					        )
 | 
				
			||||||
        this.toCacheSavers = this.initSaveToLocalStorage()
 | 
					        this.toCacheSavers = layout.enableCache ? this.initSaveToLocalStorage() : undefined
 | 
				
			||||||
        this.initActors()
 | 
					        this.initActors()
 | 
				
			||||||
        this.drawSpecialLayers()
 | 
					        this.drawSpecialLayers()
 | 
				
			||||||
        this.initHotkeys()
 | 
					        this.initHotkeys()
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue