forked from MapComplete/MapComplete
refactoring: split all the states
This commit is contained in:
parent
4d48b1cf2b
commit
8e2f04c0d0
32 changed files with 411 additions and 395 deletions
|
@ -255,7 +255,7 @@ class AddImportLayers extends DesugaringStep<LayoutConfigJson> {
|
|||
const creator = new CreateNoteImportLayer()
|
||||
for (let i1 = 0; i1 < allLayers.length; i1++) {
|
||||
const layer = allLayers[i1]
|
||||
if (Constants.priviliged_layers.indexOf(layer.id) >= 0) {
|
||||
if (layer.source === undefined) {
|
||||
// Priviliged layers are skipped
|
||||
continue
|
||||
}
|
||||
|
@ -600,7 +600,7 @@ class PreparePersonalTheme extends DesugaringStep<LayoutConfigJson> {
|
|||
// All other preparations are done by the 'override-all'-block in personal.json
|
||||
|
||||
json.layers = Array.from(this._state.sharedLayers.keys())
|
||||
.filter((l) => Constants.priviliged_layers.indexOf(l) < 0)
|
||||
.filter((l) => this._state.sharedLayers.get(l).source !== null)
|
||||
.filter((l) => this._state.publicLayers.has(l))
|
||||
return {
|
||||
result: json,
|
||||
|
|
|
@ -845,7 +845,7 @@ export class ValidateLayer extends DesugaringStep<LayerConfigJson> {
|
|||
}
|
||||
|
||||
if (json.description === undefined) {
|
||||
if (Constants.priviliged_layers.indexOf(json.id) >= 0) {
|
||||
if (typeof json.source === null) {
|
||||
errors.push(context + ": A priviliged layer must have a description")
|
||||
} else {
|
||||
warnings.push(context + ": A builtin layer should have a description")
|
||||
|
@ -882,6 +882,9 @@ export class ValidateLayer extends DesugaringStep<LayerConfigJson> {
|
|||
}
|
||||
|
||||
if (json.presets !== undefined) {
|
||||
if (typeof json.source === "string") {
|
||||
throw "A special layer cannot have presets"
|
||||
}
|
||||
// Check that a preset will be picked up by the layer itself
|
||||
const baseTags = TagUtils.Tag(json.source.osmTags)
|
||||
for (let i = 0; i < json.presets.length; i++) {
|
||||
|
|
|
@ -77,4 +77,15 @@ export default interface PointRenderingConfigJson {
|
|||
* A snippet of css-classes. They can be space-separated
|
||||
*/
|
||||
cssClasses?: string | TagRenderingConfigJson
|
||||
|
||||
/**
|
||||
* If the map is pitched, the marker will stay parallel to the screen.
|
||||
* Set to 'map' if you want to put it flattened on the map
|
||||
*/
|
||||
pitchAlignment?: "canvas" | "map" | TagRenderingConfigJson
|
||||
|
||||
/**
|
||||
* If the map is rotated, the icon will still point to the north if no rotation was applied
|
||||
*/
|
||||
rotationAlignment?: "map" | "canvas" | TagRenderingConfigJson
|
||||
}
|
||||
|
|
|
@ -86,9 +86,9 @@ export default class LayerConfig extends WithContextLoader {
|
|||
throw "Layer " + this.id + " does not define a source section (" + context + ")"
|
||||
}
|
||||
|
||||
if(json.source === "special" || json.source === "special:library"){
|
||||
if (json.source === "special" || json.source === "special:library") {
|
||||
this.source = null
|
||||
}else if (json.source.osmTags === undefined) {
|
||||
} else if (json.source.osmTags === undefined) {
|
||||
throw (
|
||||
"Layer " +
|
||||
this.id +
|
||||
|
@ -105,7 +105,6 @@ export default class LayerConfig extends WithContextLoader {
|
|||
throw `${context}: The id of a layer should match [a-z0-9-_]*: ${json.id}`
|
||||
}
|
||||
|
||||
this.maxAgeOfCache = json.source.maxCacheAge ?? 24 * 60 * 60 * 30
|
||||
if (
|
||||
json.syncSelection !== undefined &&
|
||||
LayerConfig.syncSelectionAllowed.indexOf(json.syncSelection) < 0
|
||||
|
@ -120,13 +119,28 @@ export default class LayerConfig extends WithContextLoader {
|
|||
)
|
||||
}
|
||||
this.syncSelection = json.syncSelection ?? "no"
|
||||
const osmTags = TagUtils.Tag(json.source.osmTags, context + "source.osmTags")
|
||||
if (typeof json.source !== "string") {
|
||||
this.maxAgeOfCache = json.source.maxCacheAge ?? 24 * 60 * 60 * 30
|
||||
const osmTags = TagUtils.Tag(json.source.osmTags, context + "source.osmTags")
|
||||
if (osmTags.isNegative()) {
|
||||
throw (
|
||||
context +
|
||||
"The source states tags which give a very wide selection: it only uses negative expressions, which will result in too much and unexpected data. Add at least one required tag. The tags are:\n\t" +
|
||||
osmTags.asHumanString(false, false, {})
|
||||
)
|
||||
}
|
||||
|
||||
if (Constants.priviliged_layers.indexOf(this.id) < 0 && osmTags.isNegative()) {
|
||||
throw (
|
||||
context +
|
||||
"The source states tags which give a very wide selection: it only uses negative expressions, which will result in too much and unexpected data. Add at least one required tag. The tags are:\n\t" +
|
||||
osmTags.asHumanString(false, false, {})
|
||||
this.source = new SourceConfig(
|
||||
{
|
||||
osmTags: osmTags,
|
||||
geojsonSource: json.source["geoJson"],
|
||||
geojsonSourceLevel: json.source["geoJsonZoomLevel"],
|
||||
overpassScript: json.source["overpassScript"],
|
||||
isOsmCache: json.source["isOsmCache"],
|
||||
mercatorCrs: json.source["mercatorCrs"],
|
||||
idKey: json.source["idKey"],
|
||||
},
|
||||
json.id
|
||||
)
|
||||
}
|
||||
|
||||
|
@ -138,20 +152,6 @@ export default class LayerConfig extends WithContextLoader {
|
|||
throw context + "Use 'geoJson' instead of 'geojson' (the J is a capital letter)"
|
||||
}
|
||||
|
||||
this.source = new SourceConfig(
|
||||
{
|
||||
osmTags: osmTags,
|
||||
geojsonSource: json.source["geoJson"],
|
||||
geojsonSourceLevel: json.source["geoJsonZoomLevel"],
|
||||
overpassScript: json.source["overpassScript"],
|
||||
isOsmCache: json.source["isOsmCache"],
|
||||
mercatorCrs: json.source["mercatorCrs"],
|
||||
idKey: json.source["idKey"],
|
||||
},
|
||||
Constants.priviliged_layers.indexOf(this.id) > 0,
|
||||
json.id
|
||||
)
|
||||
|
||||
this.allowSplit = json.allowSplit ?? false
|
||||
this.name = Translations.T(json.name, translationContext + ".name")
|
||||
if (json.units !== undefined && !Array.isArray(json.units)) {
|
||||
|
@ -250,7 +250,7 @@ export default class LayerConfig extends WithContextLoader {
|
|||
| "osmbasedmap"
|
||||
| "historicphoto"
|
||||
| string
|
||||
)[]
|
||||
)[]
|
||||
if (typeof pr.preciseInput.preferredBackground === "string") {
|
||||
preferredBackground = [pr.preciseInput.preferredBackground]
|
||||
} else {
|
||||
|
@ -597,7 +597,7 @@ export default class LayerConfig extends WithContextLoader {
|
|||
}
|
||||
|
||||
let overpassLink: BaseUIElement = undefined
|
||||
if (Constants.priviliged_layers.indexOf(this.id) < 0) {
|
||||
if (this.source !== undefined) {
|
||||
try {
|
||||
overpassLink = new Link(
|
||||
"Execute on overpass",
|
||||
|
|
|
@ -12,6 +12,7 @@ import Img from "../../UI/Base/Img"
|
|||
import Combine from "../../UI/Base/Combine"
|
||||
import { VariableUiElement } from "../../UI/Base/VariableUIElement"
|
||||
import { OsmTags } from "../OsmFeature"
|
||||
import { TagRenderingConfigJson } from "./Json/TagRenderingConfigJson"
|
||||
|
||||
export default class PointRenderingConfig extends WithContextLoader {
|
||||
private static readonly allowed_location_codes = new Set<string>([
|
||||
|
@ -32,6 +33,8 @@ export default class PointRenderingConfig extends WithContextLoader {
|
|||
public readonly rotation: TagRenderingConfig
|
||||
public readonly cssDef: TagRenderingConfig
|
||||
public readonly cssClasses?: TagRenderingConfig
|
||||
public readonly pitchAlignment?: TagRenderingConfig
|
||||
public readonly rotationAlignment?: TagRenderingConfig
|
||||
|
||||
constructor(json: PointRenderingConfigJson, context: string) {
|
||||
super(json, context)
|
||||
|
@ -88,6 +91,14 @@ export default class PointRenderingConfig extends WithContextLoader {
|
|||
this.iconSize = this.tr("iconSize", "40,40,center")
|
||||
this.label = this.tr("label", undefined)
|
||||
this.rotation = this.tr("rotation", "0")
|
||||
if (json.pitchAlignment) {
|
||||
console.log("Got a pitch alignment!", json.pitchAlignment)
|
||||
}
|
||||
this.pitchAlignment = this.tr("pitchAlignment", "canvas")
|
||||
this.rotationAlignment = this.tr(
|
||||
"rotationAlignment",
|
||||
json.pitchAlignment === "map" ? "map" : "canvas"
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -20,7 +20,6 @@ export default class SourceConfig {
|
|||
geojsonSourceLevel?: number
|
||||
idKey?: string
|
||||
},
|
||||
isSpecialLayer: boolean,
|
||||
context?: string
|
||||
) {
|
||||
let defined = 0
|
||||
|
@ -51,7 +50,7 @@ export default class SourceConfig {
|
|||
throw `Source defines a geojson-zoomLevel, but does not specify {x} nor {y} (or equivalent), this is probably a bug (in context ${context})`
|
||||
}
|
||||
}
|
||||
if (params.osmTags !== undefined && !isSpecialLayer) {
|
||||
if (params.osmTags !== undefined) {
|
||||
const optimized = params.osmTags.optimize()
|
||||
if (optimized === false) {
|
||||
throw (
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue