Refactoring: move 'snapToLayer' from 'preciseInput' into the preset, remove 'preferredBackground'. The addNewPointFlow _always_ shows the precise input flow with the basic map; so the preferredBackground became irrelevant

This commit is contained in:
Pieter Vander Vennet 2023-06-20 01:52:15 +02:00
parent ecf5c3cbe5
commit a6f7b1300a
127 changed files with 209 additions and 345 deletions

View file

@ -34,6 +34,25 @@ export class UpdateLegacyLayer extends DesugaringStep<
delete config["overpassTags"]
}
for (const preset of config.presets ?? []) {
const preciseInput = preset["preciseInput"]
if (typeof preciseInput === "boolean") {
delete preset["preciseInput"]
} else if (preciseInput !== undefined) {
delete preciseInput["preferredBackground"]
console.log("Precise input:", preciseInput)
preset.snapToLayer = preciseInput.snapToLayer
delete preciseInput.snapToLayer
if (preciseInput.maxSnapDistance) {
preset.maxSnapDistance = preciseInput.maxSnapDistance
delete preciseInput.maxSnapDistance
}
if (Object.keys(preciseInput).length == 0) {
delete preset["preciseInput"]
}
}
}
if (config.tagRenderings !== undefined) {
let i = 0
for (const tagRendering of config.tagRenderings) {

View file

@ -233,36 +233,16 @@ export interface LayerConfigJson {
exampleImages?: string[]
/**
* If set, the user will prompted to confirm the location before actually adding the data.
* This will be with a 'drag crosshair'-method.
*
* If 'preferredBackgroundCategory' is set, the element will attempt to pick a background layer of that category.
* If specified, these layers will be shown to and the new point will be snapped towards it
*/
preciseInput?:
| true
| {
/**
* The type of background picture
*/
preferredBackground?:
| "osmbasedmap"
| "photo"
| "historicphoto"
| "map"
| string
| string[]
/**
* If specified, these layers will be shown to and the new point will be snapped towards it
*/
snapToLayer?: string | string[]
/**
* If specified, a new point will only be snapped if it is within this range.
* Distance in meter
*
* Default: 10
*/
maxSnapDistance?: number
}
snapToLayer?: string | string[]
/**
* If specified, a new point will only be snapped if it is within this range.
* Distance in meter
*
* Default: 10
*/
maxSnapDistance?: number
}[]
/**

View file

@ -234,37 +234,27 @@ export default class LayerConfig extends WithContextLoader {
snapToLayers: undefined,
maxSnapDistance: undefined,
}
if (pr.preciseInput !== undefined) {
if (pr.preciseInput === true) {
pr.preciseInput = {
preferredBackground: undefined,
}
}
if (pr["preciseInput"] !== undefined) {
throw "Layer " + this.id + " still uses the old 'preciseInput'-field"
}
if (pr.snapToLayer !== undefined) {
let snapToLayers: string[]
if (typeof pr.preciseInput.snapToLayer === "string") {
snapToLayers = [pr.preciseInput.snapToLayer]
if (typeof pr.snapToLayer === "string") {
snapToLayers = [pr.snapToLayer]
} else {
snapToLayers = pr.preciseInput.snapToLayer
snapToLayers = pr.snapToLayer
}
let preferredBackground: (
| "map"
| "photo"
| "osmbasedmap"
| "historicphoto"
| string
)[]
if (typeof pr.preciseInput.preferredBackground === "string") {
preferredBackground = [pr.preciseInput.preferredBackground]
} else {
preferredBackground = pr.preciseInput.preferredBackground
}
preciseInput = {
preferredBackground,
snapToLayers,
maxSnapDistance: pr.preciseInput.maxSnapDistance ?? 10,
maxSnapDistance: pr.maxSnapDistance ?? 10,
}
} else if (pr.maxSnapDistance !== undefined) {
throw (
"Layer " +
this.id +
" defines a maxSnapDistance, but does not include a `snapToLayer`"
)
}
const config: PresetConfig = {