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
|
@ -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))
|
||||
|
@ -330,8 +336,12 @@ 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