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 FullNodeDatabaseSource from "./TiledFeatureSource/FullNodeDatabaseSource";
|
||||||
import MapState from "../State/MapState";
|
import MapState from "../State/MapState";
|
||||||
import {ElementStorage} from "../ElementStorage";
|
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 {
|
private freshnessForVisibleLayers(z: number, x: number, y: number): Date {
|
||||||
let oldestDate = undefined;
|
let oldestDate = undefined;
|
||||||
for (const flayer of this.state.filteredLayers.data) {
|
for (const flayer of this.state.filteredLayers.data) {
|
||||||
if (!flayer.isDisplayed.data) {
|
if (!flayer.isDisplayed.data && !flayer.layerDef.forceLoad) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if (this.state.locationControl.data.zoom < flayer.layerDef.minzoom) {
|
if (this.state.locationControl.data.zoom < flayer.layerDef.minzoom) {
|
||||||
|
@ -399,6 +398,9 @@ export default class FeaturePipeline {
|
||||||
return oldestDate
|
return oldestDate
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Gives an UIEventSource containing the tileIndexes of the tiles that should be loaded from OSM
|
||||||
|
* */
|
||||||
private getNeededTilesFromOsm(isSufficientlyZoomed: UIEventSource<boolean>): UIEventSource<number[]> {
|
private getNeededTilesFromOsm(isSufficientlyZoomed: UIEventSource<boolean>): UIEventSource<number[]> {
|
||||||
const self = this
|
const self = this
|
||||||
return this.state.currentBounds.map(bbox => {
|
return this.state.currentBounds.map(bbox => {
|
||||||
|
|
|
@ -27,7 +27,7 @@ export default class DynamicTileSource implements TileHierarchy<FeatureSourceFor
|
||||||
this.loadedTiles = new Map<number, FeatureSourceForLayer & Tiled>()
|
this.loadedTiles = new Map<number, FeatureSourceForLayer & Tiled>()
|
||||||
const neededTiles = state.locationControl.map(
|
const neededTiles = state.locationControl.map(
|
||||||
location => {
|
location => {
|
||||||
if (!layer.isDisplayed.data) {
|
if (!layer.isDisplayed.data && !layer.layerDef.forceLoad) {
|
||||||
// No need to download! - the layer is disabled
|
// No need to download! - the layer is disabled
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,7 +10,6 @@ import LayerConfig from "../LayerConfig";
|
||||||
import {TagRenderingConfigJson} from "../Json/TagRenderingConfigJson";
|
import {TagRenderingConfigJson} from "../Json/TagRenderingConfigJson";
|
||||||
import {SubstitutedTranslation} from "../../../UI/SubstitutedTranslation";
|
import {SubstitutedTranslation} from "../../../UI/SubstitutedTranslation";
|
||||||
import DependencyCalculator from "../DependencyCalculator";
|
import DependencyCalculator from "../DependencyCalculator";
|
||||||
import {ValidateThemeAndLayers} from "./Validation";
|
|
||||||
|
|
||||||
class SubstituteLayer extends Conversion<(string | LayerConfigJson), LayerConfigJson[]> {
|
class SubstituteLayer extends Conversion<(string | LayerConfigJson), LayerConfigJson[]> {
|
||||||
private readonly _state: DesugaringContext;
|
private readonly _state: DesugaringContext;
|
||||||
|
@ -306,6 +305,13 @@ class AddDependencyLayersToTheme extends DesugaringStep<LayoutConfigJson> {
|
||||||
dependencies.push(...layerDeps)
|
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
|
// 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
|
// Their existance is checked elsewhere, so this is fine
|
||||||
unmetDependencies = dependencies.filter(dep => !loadedLayerIds.has(dep.neededLayer))
|
unmetDependencies = dependencies.filter(dep => !loadedLayerIds.has(dep.neededLayer))
|
||||||
|
@ -330,8 +336,12 @@ class AddDependencyLayersToTheme extends DesugaringStep<LayoutConfigJson> {
|
||||||
}
|
}
|
||||||
|
|
||||||
} while (unmetDependencies.length > 0)
|
} 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[] } {
|
convert(theme: LayoutConfigJson, context: string): { result: LayoutConfigJson; errors: string[]; warnings: string[] } {
|
||||||
|
|
|
@ -111,6 +111,13 @@ export interface LayerConfigJson {
|
||||||
*/
|
*/
|
||||||
isShown?: TagRenderingConfigJson;
|
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
|
* 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 tagRenderings: TagRenderingConfig[];
|
||||||
public readonly filters: FilterConfig[];
|
public readonly filters: FilterConfig[];
|
||||||
public readonly filterIsSameAs: string;
|
public readonly filterIsSameAs: string;
|
||||||
|
public readonly forceLoad: boolean;
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
json: LayerConfigJson,
|
json: LayerConfigJson,
|
||||||
|
@ -166,6 +167,7 @@ export default class LayerConfig extends WithContextLoader {
|
||||||
this.minzoom = json.minzoom ?? 0;
|
this.minzoom = json.minzoom ?? 0;
|
||||||
this.minzoomVisible = json.minzoomVisible ?? this.minzoom;
|
this.minzoomVisible = json.minzoomVisible ?? this.minzoom;
|
||||||
this.shownByDefault = json.shownByDefault ?? true;
|
this.shownByDefault = json.shownByDefault ?? true;
|
||||||
|
this.forceLoad = json.forceLoad ?? false;
|
||||||
if (json.presets !== undefined && json.presets?.map === undefined) {
|
if (json.presets !== undefined && json.presets?.map === undefined) {
|
||||||
throw "Presets should be a list of items (at " + context + ")"
|
throw "Presets should be a list of items (at " + context + ")"
|
||||||
}
|
}
|
||||||
|
|
|
@ -56,4 +56,4 @@
|
||||||
],
|
],
|
||||||
"sources": []
|
"sources": []
|
||||||
}
|
}
|
||||||
]
|
]
|
Loading…
Add table
Add a link
Reference in a new issue