Add overlay layer possibility, fix #515

This commit is contained in:
Pieter Vander Vennet 2021-10-14 21:43:14 +02:00
parent 7e053b3ada
commit 891c449058
12 changed files with 263 additions and 56 deletions

View file

@ -1,5 +1,7 @@
import {TagRenderingConfigJson} from "./TagRenderingConfigJson";
import {LayerConfigJson} from "./LayerConfigJson";
import TilesourceConfig from "../TilesourceConfig";
import TilesourceConfigJson from "./TilesourceConfigJson";
/**
* Defines the entire theme.
@ -155,6 +157,11 @@ export interface LayoutConfigJson {
*/
defaultBackgroundId?: string;
/**
* Define some (overlay) slippy map tilesources
*/
tileLayerSources?: TilesourceConfigJson[]
/**
* The number of seconds that a feature is allowed to stay in the cache.
* The caching flow is as following:

View file

@ -0,0 +1,36 @@
/**
* Configuration for a tilesource config
*/
export default interface TilesourceConfigJson {
/**
* The path, where {x}, {y} and {z} will be substituted
*/
source: string,
isOverlay?: boolean,
/**
* How this will be shown in the selection menu.
* Make undefined if this may not be toggled
*/
name?: any | string
/**
* Only visible at this or a higher zoom level
*/
minZoom?: number
/**
* Only visible at this or a lower zoom level
*/
maxZoom?: number
/**
* The default state, set to false to hide by default
*/
defaultState: boolean;
}

View file

@ -7,6 +7,7 @@ import {Utils} from "../../Utils";
import LayerConfig from "./LayerConfig";
import {LayerConfigJson} from "./Json/LayerConfigJson";
import Constants from "../Constants";
import TilesourceConfig from "./TilesourceConfig";
export default class LayoutConfig {
public readonly id: string;
@ -27,6 +28,7 @@ export default class LayoutConfig {
public readonly roamingRenderings: TagRenderingConfig[];
public readonly defaultBackgroundId?: string;
public layers: LayerConfig[];
public tileLayerSources: TilesourceConfig[]
public readonly clustering?: {
maxZoom: number,
minNeededElements: number,
@ -108,6 +110,7 @@ export default class LayoutConfig {
}
);
this.defaultBackgroundId = json.defaultBackgroundId;
this.tileLayerSources = (json.tileLayerSources??[]).map((config, i) => new TilesourceConfig(config, `${this.id}.tileLayerSources[${i}]`))
this.layers = LayoutConfig.ExtractLayers(json, official, context);
// ALl the layers are constructed, let them share tagRenderings now!

View file

@ -0,0 +1,38 @@
import TilesourceConfigJson from "./Json/TilesourceConfigJson";
import Translations from "../../UI/i18n/Translations";
import {Translation} from "../../UI/i18n/Translation";
export default class TilesourceConfig {
public readonly source: string
public readonly isOverlay: boolean
public readonly name: Translation
public readonly minzoom: number
public readonly maxzoom: number
public readonly defaultState: boolean;
constructor(config: TilesourceConfigJson, ctx: string = "") {
this.source = config.source;
this.isOverlay = config.isOverlay ?? false;
this.name = Translations.T(config.name)
this.minzoom = config.minZoom ?? 0
this.maxzoom = config.maxZoom ?? 999
this.defaultState = config.defaultState ?? true;
if (this.minzoom > this.maxzoom) {
throw "Invalid tilesourceConfig: minzoom should be smaller then maxzoom (at " + ctx + ")"
}
if (this.minzoom < 0) {
throw "minzoom should be > 0 (at " + ctx + ")"
}
if (this.maxzoom < 0) {
throw "maxzoom should be > 0 (at " + ctx + ")"
}
if (this.source.indexOf("{zoom}") >= 0) {
throw "Invalid source url: use {z} instead of {zoom} (at " + ctx + ".source)"
}
if(!this.defaultState && config.name === undefined){
throw "Disabling an overlay without a name is not possible"
}
}
}