forked from MapComplete/MapComplete
Feature(distancePicker): revive geographical distance picker
This commit is contained in:
parent
e997653284
commit
5095bffc50
16 changed files with 245 additions and 107 deletions
55
src/UI/InputElement/Validators/DistanceValidator.ts
Normal file
55
src/UI/InputElement/Validators/DistanceValidator.ts
Normal file
|
|
@ -0,0 +1,55 @@
|
|||
import { Validator } from "../Validator"
|
||||
import { Utils } from "../../../Utils"
|
||||
import { eliCategory } from "../../../Models/RasterLayerProperties"
|
||||
|
||||
export default class DistanceValidator extends Validator {
|
||||
private readonly docs: string = [
|
||||
"#### Helper-arguments",
|
||||
"Options are:",
|
||||
["````json",
|
||||
" \"background\": \"some_background_id or category, e.g. 'map'\"",
|
||||
" \"zoom\": 20 # initial zoom level of the map",
|
||||
"}",
|
||||
"```"].join("\n")
|
||||
].join("\n\n")
|
||||
|
||||
constructor() {
|
||||
super(
|
||||
"distance",
|
||||
"A geographical distance in meters (rounded at two points). Will give an extra minimap with a measurement tool. Arguments: [ zoomlevel, preferredBackgroundMapType (comma separated) ], e.g. `[\"21\", \"map,photo\"]",
|
||||
"decimal"
|
||||
)
|
||||
}
|
||||
|
||||
isValid = (str) => {
|
||||
const t = Number(str)
|
||||
return !isNaN(t)
|
||||
}
|
||||
|
||||
validateArguments(args: any): undefined | string {
|
||||
if (args === undefined) {
|
||||
return undefined
|
||||
}
|
||||
if (typeof args !== "object" || Array.isArray(args)) {
|
||||
return "Expected an object of type `{background?: string, zoom?: number}`"
|
||||
}
|
||||
|
||||
const optionalKeys = ["background", "zoom"]
|
||||
const keys = Object.keys(args).filter(k => optionalKeys.indexOf(k) < 0)
|
||||
if (keys.length > 0) {
|
||||
return "Unknown key " + keys.join("; ") + "; use " + optionalKeys.join("; ") + " instead"
|
||||
}
|
||||
const bg = args["background"]
|
||||
if (bg && eliCategory.indexOf(bg) < 0) {
|
||||
return "The given background layer is not a recognized ELI-type. Perhaps you meant one of " +
|
||||
Utils.sortedByLevenshteinDistance(bg, eliCategory, x => x).slice(0, 5)
|
||||
}
|
||||
if (typeof args["zoom"] !== "number") {
|
||||
return "zoom must be a number, got a " + typeof args["zoom"]
|
||||
}
|
||||
if (typeof args["zoom"] !== "number" || args["zoom"] <= 1 || args["zoom"] > 25) {
|
||||
return "zoom must be a number between 2 and 25, got " + args["zoom"]
|
||||
}
|
||||
return undefined
|
||||
}
|
||||
}
|
||||
|
|
@ -4,7 +4,7 @@ import { Validator } from "../Validator"
|
|||
import { ValidatorType } from "../Validators"
|
||||
|
||||
export default class FloatValidator extends Validator {
|
||||
inputmode: "decimal" = "decimal"
|
||||
inputmode: "decimal" = "decimal" as const
|
||||
|
||||
constructor(name?: ValidatorType, explanation?: string) {
|
||||
super(name ?? "float", explanation ?? "A decimal number", "decimal")
|
||||
|
|
|
|||
|
|
@ -1,16 +0,0 @@
|
|||
import { Validator } from "../Validator"
|
||||
|
||||
export default class LengthValidator extends Validator {
|
||||
constructor() {
|
||||
super(
|
||||
"distance",
|
||||
'A geographical distance in meters (rounded at two points). Will give an extra minimap with a measurement tool. Arguments: [ zoomlevel, preferredBackgroundMapType (comma separated) ], e.g. `["21", "map,photo"]',
|
||||
"decimal"
|
||||
)
|
||||
}
|
||||
|
||||
isValid = (str) => {
|
||||
const t = Number(str)
|
||||
return !isNaN(t)
|
||||
}
|
||||
}
|
||||
|
|
@ -1,40 +1,14 @@
|
|||
import Title from "../../Base/Title"
|
||||
import Combine from "../../Base/Combine"
|
||||
import { Validator } from "../Validator"
|
||||
import Table from "../../Base/Table"
|
||||
|
||||
export default class NameSuggestionIndexValidator extends Validator {
|
||||
constructor() {
|
||||
super(
|
||||
"nsi",
|
||||
new Combine([
|
||||
"Gives a list of possible suggestions for a brand or operator tag.",
|
||||
new Title("Helper arguments"),
|
||||
new Table(
|
||||
["name", "doc"],
|
||||
[
|
||||
[
|
||||
"options",
|
||||
new Combine([
|
||||
"A JSON-object of type `{ main: string, key: string }`. ",
|
||||
new Table(
|
||||
["subarg", "doc"],
|
||||
[
|
||||
[
|
||||
"main",
|
||||
"The main tag to give suggestions for, e.g. `amenity=restaurant`.",
|
||||
],
|
||||
[
|
||||
"addExtraTags",
|
||||
"Extra tags to add to the suggestions, e.g. `nobrand=yes`.",
|
||||
],
|
||||
]
|
||||
),
|
||||
]),
|
||||
],
|
||||
]
|
||||
),
|
||||
])
|
||||
"Gives a list of possible suggestions for a brand or operator tag. Note: this is detected automatically; there is no need to explicitly set this"
|
||||
)
|
||||
}
|
||||
|
||||
validateArguments(args: string): string | undefined {
|
||||
return "No arguments needed"
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue