mapcomplete/Models/ThemeConfig/SourceConfig.ts

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

80 lines
2.9 KiB
TypeScript
Raw Normal View History

2021-03-29 00:41:53 +02:00
import { TagsFilter } from "../../Logic/Tags/TagsFilter"
import { RegexTag } from "../../Logic/Tags/RegexTag"
export default class SourceConfig {
2022-09-14 14:43:14 +02:00
public osmTags?: TagsFilter
public readonly overpassScript?: string
2021-12-07 17:46:57 +01:00
public geojsonSource?: string
public geojsonZoomLevel?: number
public isOsmCacheLayer: boolean
2021-11-07 16:34:51 +01:00
public readonly mercatorCrs: boolean
public readonly idKey: string
constructor(
params: {
mercatorCrs?: boolean
osmTags?: TagsFilter
overpassScript?: string
2021-12-07 17:46:57 +01:00
geojsonSource?: string
isOsmCache?: boolean
geojsonSourceLevel?: number
idKey?: string
},
isSpecialLayer: boolean,
context?: string
) {
let defined = 0
if (params.osmTags) {
defined++
}
if (params.overpassScript) {
defined++
}
if (params.geojsonSource) {
defined++
}
if (defined == 0) {
2021-05-17 00:31:10 +02:00
throw `Source: nothing correct defined in the source (in ${context}) (the params are ${JSON.stringify(
params
)})`
}
if (params.isOsmCache && params.geojsonSource == undefined) {
console.error(params)
throw `Source said it is a OSM-cached layer, but didn't define the actual source of the cache (in context ${context})`
}
2021-11-07 16:34:51 +01:00
if (params.geojsonSource !== undefined && params.geojsonSourceLevel !== undefined) {
if (
!["x", "y", "x_min", "x_max", "y_min", "Y_max"].some(
(toSearch) => params.geojsonSource.indexOf(toSearch) > 0
2022-09-08 21:40:48 +02:00
)
2021-11-07 16:34:51 +01:00
) {
throw `Source defines a geojson-zoomLevel, but does not specify {x} nor {y} (or equivalent), this is probably a bug (in context ${context})`
2021-11-07 16:34:51 +01:00
}
}
if (params.osmTags !== undefined && !isSpecialLayer) {
const optimized = params.osmTags.optimize()
if (optimized === false) {
throw (
"Error at " +
context +
": the specified tags are conflicting with each other: they will never match anything at all"
2022-09-08 21:40:48 +02:00
)
}
if (optimized === true) {
throw (
"Error at " +
context +
": the specified tags are very wide: they will always match everything"
2022-09-08 21:40:48 +02:00
)
}
}
2021-11-07 16:34:51 +01:00
this.osmTags = params.osmTags ?? new RegexTag("id", /.*/)
this.overpassScript = params.overpassScript
this.geojsonSource = params.geojsonSource
this.geojsonZoomLevel = params.geojsonSourceLevel
this.isOsmCacheLayer = params.isOsmCache ?? false
this.mercatorCrs = params.mercatorCrs ?? false
this.idKey = params.idKey
}
}