forked from MapComplete/MapComplete
		
	Add option to force loading of a layer, even if it is hidden + automatically set this flag is another layer depends on this layer
This commit is contained in:
		
							parent
							
								
									ad2f7b2bd6
								
							
						
					
					
						commit
						0f95891a47
					
				
					 6 changed files with 28 additions and 7 deletions
				
			
		|  | @ -23,7 +23,6 @@ import TileFreshnessCalculator from "./TileFreshnessCalculator"; | |||
| import FullNodeDatabaseSource from "./TiledFeatureSource/FullNodeDatabaseSource"; | ||||
| import MapState from "../State/MapState"; | ||||
| import {ElementStorage} from "../ElementStorage"; | ||||
| import MetaTagging from "../MetaTagging"; | ||||
| 
 | ||||
| 
 | ||||
| /** | ||||
|  | @ -373,7 +372,7 @@ export default class FeaturePipeline { | |||
|     private freshnessForVisibleLayers(z: number, x: number, y: number): Date { | ||||
|         let oldestDate = undefined; | ||||
|         for (const flayer of this.state.filteredLayers.data) { | ||||
|             if (!flayer.isDisplayed.data) { | ||||
|             if (!flayer.isDisplayed.data && !flayer.layerDef.forceLoad) { | ||||
|                 continue | ||||
|             } | ||||
|             if (this.state.locationControl.data.zoom < flayer.layerDef.minzoom) { | ||||
|  | @ -399,6 +398,9 @@ export default class FeaturePipeline { | |||
|         return oldestDate | ||||
|     } | ||||
| 
 | ||||
|     /* | ||||
|     * Gives an UIEventSource containing the tileIndexes of the tiles that should be loaded from OSM | ||||
|     * */ | ||||
|     private getNeededTilesFromOsm(isSufficientlyZoomed: UIEventSource<boolean>): UIEventSource<number[]> { | ||||
|         const self = this | ||||
|         return this.state.currentBounds.map(bbox => { | ||||
|  |  | |||
|  | @ -27,7 +27,7 @@ export default class DynamicTileSource implements TileHierarchy<FeatureSourceFor | |||
|         this.loadedTiles = new Map<number, FeatureSourceForLayer & Tiled>() | ||||
|         const neededTiles = state.locationControl.map( | ||||
|             location => { | ||||
|                 if (!layer.isDisplayed.data) { | ||||
|                 if (!layer.isDisplayed.data && !layer.layerDef.forceLoad) { | ||||
|                     // No need to download! - the layer is disabled
 | ||||
|                     return undefined; | ||||
|                 } | ||||
|  |  | |||
|  | @ -10,7 +10,6 @@ import LayerConfig from "../LayerConfig"; | |||
| import {TagRenderingConfigJson} from "../Json/TagRenderingConfigJson"; | ||||
| import {SubstitutedTranslation} from "../../../UI/SubstitutedTranslation"; | ||||
| import DependencyCalculator from "../DependencyCalculator"; | ||||
| import {ValidateThemeAndLayers} from "./Validation"; | ||||
| 
 | ||||
| class SubstituteLayer extends Conversion<(string | LayerConfigJson), LayerConfigJson[]> { | ||||
|     private readonly _state: DesugaringContext; | ||||
|  | @ -306,6 +305,13 @@ class AddDependencyLayersToTheme extends DesugaringStep<LayoutConfigJson> { | |||
|                 dependencies.push(...layerDeps) | ||||
|             } | ||||
| 
 | ||||
|             for (const dependency of dependencies) { | ||||
|                 if(loadedLayerIds.has(dependency.neededLayer)){ | ||||
|                     // We mark the needed layer as 'mustLoad'
 | ||||
|                     alreadyLoaded.find(l => l.id === dependency.neededLayer).forceLoad = true | ||||
|                 } | ||||
|             } | ||||
| 
 | ||||
|             // During the generate script, builtin layers are verified but not loaded - so we have to add them manually here
 | ||||
|             // Their existance is checked elsewhere, so this is fine
 | ||||
|             unmetDependencies = dependencies.filter(dep => !loadedLayerIds.has(dep.neededLayer)) | ||||
|  | @ -331,7 +337,11 @@ class AddDependencyLayersToTheme extends DesugaringStep<LayoutConfigJson> { | |||
| 
 | ||||
|         } while (unmetDependencies.length > 0) | ||||
|          | ||||
|         return dependenciesToAdd; | ||||
|         return dependenciesToAdd.map(dep => { | ||||
|             dep = Utils.Clone(dep); | ||||
|             dep.forceLoad = true | ||||
|             return dep | ||||
|         }); | ||||
|     } | ||||
| 
 | ||||
|     convert(theme: LayoutConfigJson, context: string): { result: LayoutConfigJson; errors: string[]; warnings: string[] } { | ||||
|  |  | |||
|  | @ -111,6 +111,13 @@ export interface LayerConfigJson { | |||
|      */ | ||||
|     isShown?: TagRenderingConfigJson; | ||||
| 
 | ||||
|     /** | ||||
|      * Advanced option - might be set by the theme compiler | ||||
|      *  | ||||
|      * If true, this data will _always_ be loaded, even if the theme is disabled | ||||
|      */ | ||||
|     forceLoad?: false | boolean | ||||
| 
 | ||||
| 
 | ||||
|     /** | ||||
|      * The minimum needed zoomlevel required before loading of the data start | ||||
|  |  | |||
|  | @ -60,6 +60,7 @@ export default class LayerConfig extends WithContextLoader { | |||
|     public readonly tagRenderings: TagRenderingConfig[]; | ||||
|     public readonly filters: FilterConfig[]; | ||||
|     public readonly filterIsSameAs: string; | ||||
|     public readonly forceLoad: boolean; | ||||
|      | ||||
|     constructor( | ||||
|         json: LayerConfigJson, | ||||
|  | @ -166,6 +167,7 @@ export default class LayerConfig extends WithContextLoader { | |||
|         this.minzoom = json.minzoom ?? 0; | ||||
|         this.minzoomVisible = json.minzoomVisible ?? this.minzoom; | ||||
|         this.shownByDefault = json.shownByDefault ?? true; | ||||
|         this.forceLoad = json.forceLoad ?? false; | ||||
|         if (json.presets !== undefined && json.presets?.map === undefined) { | ||||
|             throw "Presets should be a list of items (at " + context + ")" | ||||
|         } | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue