Add move option, enable move and delete option on most layers

This commit is contained in:
Pieter Vander Vennet 2021-10-14 03:46:09 +02:00
parent 0a3eb966c1
commit 7e2b73ac5d
33 changed files with 454 additions and 104 deletions

View file

@ -3,6 +3,7 @@ import {TagRenderingConfigJson} from "./TagRenderingConfigJson";
import FilterConfigJson from "./FilterConfigJson";
import {DeleteConfigJson} from "./DeleteConfigJson";
import UnitConfigJson from "./UnitConfigJson";
import MoveConfigJson from "./MoveConfigJson";
/**
* Configuration for a single layer
@ -314,6 +315,18 @@ export interface LayerConfigJson {
*/
deletion?: boolean | DeleteConfigJson
/**
* Indicates if a point can be moved and configures the modalities.
*
* A feature can be moved by MapComplete if:
*
* - It is a point
* - The point is _not_ part of a way or a a relation.
*
* Off by default. Can be enabled by setting this flag or by configuring.
*/
allowMove?: boolean | MoveConfigJson
/**
* IF set, a 'split this road' button is shown
*/

View file

@ -0,0 +1,12 @@
export default interface MoveConfigJson {
/**
* One default reason to move a point is to improve accuracy.
* Set to false to disable this reason
*/
enableImproveAccuracy?: true | boolean
/**
* One default reason to move a point is because it has relocated
* Set to false to disable this reason
*/
enableRelocation?: true | boolean
}

View file

@ -19,6 +19,7 @@ import {Unit} from "../Unit";
import DeleteConfig from "./DeleteConfig";
import Svg from "../../Svg";
import Img from "../../UI/Base/Img";
import MoveConfig from "./MoveConfig";
export default class LayerConfig {
static WAYHANDLING_DEFAULT = 0;
@ -49,6 +50,7 @@ export default class LayerConfig {
wayHandling: number;
public readonly units: Unit[];
public readonly deletion: DeleteConfig | null;
public readonly allowMove: MoveConfig | null
public readonly allowSplit: boolean
presets: PresetConfig[];
@ -67,7 +69,7 @@ export default class LayerConfig {
this.id = json.id;
this.allowSplit = json.allowSplit ?? false;
this.name = Translations.T(json.name, context + ".name");
this.units = (json.units ?? []).map(((unitJson, i) => Unit.fromJson(unitJson, `${context}.unit[${i}]`)))
this.units = (json.units ?? []).map(((unitJson, i) => Unit.fromJson(unitJson, `${context}.unit[${i}]`)))
if (json.description !== undefined) {
if (Object.keys(json.description).length === 0) {
@ -138,11 +140,11 @@ export default class LayerConfig {
const key = kv.substring(0, index);
const code = kv.substring(index + 1);
try{
new Function("feat", "return " + code + ";");
}catch(e){
throw `Invalid function definition: code ${code} is invalid:${e} (at ${context})`
try {
new Function("feat", "return " + code + ";");
} catch (e) {
throw `Invalid function definition: code ${code} is invalid:${e} (at ${context})`
}
@ -155,8 +157,8 @@ export default class LayerConfig {
this.minzoom = json.minzoom ?? 0;
this.minzoomVisible = json.minzoomVisible ?? this.minzoom;
this.wayHandling = json.wayHandling ?? 0;
if(json.presets !== undefined && json.presets?.map === undefined){
throw "Presets should be a list of items (at "+context+")"
if (json.presets !== undefined && json.presets?.map === undefined) {
throw "Presets should be a list of items (at " + context + ")"
}
this.presets = (json.presets ?? []).map((pr, i) => {
@ -291,21 +293,21 @@ export default class LayerConfig {
}
this.tagRenderings = trs(json.tagRenderings, false);
const missingIds = json.tagRenderings?.filter(tr => typeof tr !== "string" && tr["builtin"] === undefined && tr["id"] === undefined) ?? [];
if(missingIds.length > 0 && official){
console.error("Some tagRenderings of", this.id, "are missing an id:", missingIds)
throw "Missing ids in tagrenderings"
}
const missingIds = json.tagRenderings?.filter(tr => typeof tr !== "string" && tr["builtin"] === undefined && tr["id"] === undefined) ?? [];
if (missingIds.length > 0 && official) {
console.error("Some tagRenderings of", this.id, "are missing an id:", missingIds)
throw "Missing ids in tagrenderings"
}
this.filters = (json.filter ?? []).map((option, i) => {
return new FilterConfig(option, `${context}.filter-[${i}]`)
});
if(json["filters"] !== undefined){
throw "Error in "+context+": use 'filter' instead of 'filters'"
}
if (json["filters"] !== undefined) {
throw "Error in " + context + ": use 'filter' instead of 'filters'"
}
const titleIcons = [];
const defaultIcons = [
@ -369,6 +371,16 @@ export default class LayerConfig {
this.deletion = new DeleteConfig(json.deletion, `${context}.deletion`);
}
this.allowMove = null
if (json.allowMove === false) {
this.allowMove = null;
} else if (json.allowMove === true) {
this.allowMove = new MoveConfig({}, context + ".allowMove")
} else if (json.allowMove !== undefined && json.allowMove !== false) {
this.allowMove = new MoveConfig(json.allowMove, context + ".allowMove")
}
if (json["showIf"] !== undefined) {
throw (
"Invalid key on layerconfig " +

View file

@ -0,0 +1,17 @@
import MoveConfigJson from "./Json/MoveConfigJson";
export default class MoveConfig {
public readonly enableImproveAccuracy: boolean
public readonly enableRelocation: boolean
constructor(json: MoveConfigJson, context: string) {
this.enableImproveAccuracy = json.enableImproveAccuracy ?? true
this.enableRelocation = json.enableRelocation ?? true
if (!(this.enableRelocation || this.enableImproveAccuracy)) {
throw "At least one default move reason should be allowed (at " + context + ")"
}
}
}