forked from MapComplete/MapComplete
Fix overlay layers
This commit is contained in:
parent
3aeedf22c8
commit
24f7610d0a
15 changed files with 216 additions and 184 deletions
|
@ -1,6 +1,6 @@
|
|||
import { LayerConfigJson } from "./LayerConfigJson"
|
||||
import TilesourceConfigJson from "./TilesourceConfigJson"
|
||||
import ExtraLinkConfigJson from "./ExtraLinkConfigJson"
|
||||
import { RasterLayerProperties } from "../../RasterLayers"
|
||||
|
||||
/**
|
||||
* Defines the entire theme.
|
||||
|
@ -148,7 +148,7 @@ export interface LayoutConfigJson {
|
|||
/**
|
||||
* Define some (overlay) slippy map tilesources
|
||||
*/
|
||||
tileLayerSources?: TilesourceConfigJson[]
|
||||
tileLayerSources?: (RasterLayerProperties & { defaultState?: true | boolean })[]
|
||||
|
||||
/**
|
||||
* The layers to display.
|
||||
|
|
|
@ -3,11 +3,12 @@ import { LayoutConfigJson } from "./Json/LayoutConfigJson"
|
|||
import LayerConfig from "./LayerConfig"
|
||||
import { LayerConfigJson } from "./Json/LayerConfigJson"
|
||||
import Constants from "../Constants"
|
||||
import TilesourceConfig from "./TilesourceConfig"
|
||||
import { ExtractImages } from "./Conversion/FixImages"
|
||||
import ExtraLinkConfig from "./ExtraLinkConfig"
|
||||
import { Utils } from "../../Utils"
|
||||
import LanguageUtils from "../../Utils/LanguageUtils"
|
||||
import { RasterLayerProperties } from "../RasterLayers"
|
||||
|
||||
/**
|
||||
* Minimal information about a theme
|
||||
**/
|
||||
|
@ -39,7 +40,7 @@ export default class LayoutConfig implements LayoutInformation {
|
|||
public widenFactor: number
|
||||
public defaultBackgroundId?: string
|
||||
public layers: LayerConfig[]
|
||||
public tileLayerSources: TilesourceConfig[]
|
||||
public tileLayerSources: (RasterLayerProperties & { defaultState?: true | boolean })[]
|
||||
public readonly hideFromOverview: boolean
|
||||
public lockLocation: boolean | [[number, number], [number, number]]
|
||||
public readonly enableUserBadge: boolean
|
||||
|
@ -161,9 +162,7 @@ export default class LayoutConfig implements LayoutInformation {
|
|||
this.widenFactor = json.widenFactor ?? 1.5
|
||||
|
||||
this.defaultBackgroundId = json.defaultBackgroundId
|
||||
this.tileLayerSources = (json.tileLayerSources ?? []).map(
|
||||
(config, i) => new TilesourceConfig(config, `${this.id}.tileLayerSources[${i}]`)
|
||||
)
|
||||
this.tileLayerSources = json.tileLayerSources ?? []
|
||||
// At this point, layers should be expanded and validated either by the generateScript or the LegacyJsonConvert
|
||||
this.layers = json.layers.map(
|
||||
(lyrJson) =>
|
||||
|
|
|
@ -1,43 +0,0 @@
|
|||
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 id: 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.id = config.id
|
||||
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.id === undefined) {
|
||||
throw "An id is obligated"
|
||||
}
|
||||
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