forked from MapComplete/MapComplete
Add overlay layer possibility, fix #515
This commit is contained in:
parent
7e053b3ada
commit
891c449058
12 changed files with 263 additions and 56 deletions
38
Models/ThemeConfig/TilesourceConfig.ts
Normal file
38
Models/ThemeConfig/TilesourceConfig.ts
Normal 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"
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue