From fdf38daf5e9f984dcf3d05c95db4fa89afeb5ef6 Mon Sep 17 00:00:00 2001 From: Pieter Vander Vennet Date: Thu, 14 Dec 2023 15:41:34 +0100 Subject: [PATCH] Feature: add slope measurement input --- .../cycleways_and_roads.json | 35 +++++++++++++++++++ langs/en.json | 17 +++++++++ src/UI/InputElement/Helpers/SlopeInput.svelte | 0 src/UI/InputElement/InputHelpers.ts | 7 ---- .../InputElement/Validators/SlopeValidator.ts | 13 +++++++ 5 files changed, 65 insertions(+), 7 deletions(-) create mode 100644 src/UI/InputElement/Helpers/SlopeInput.svelte create mode 100644 src/UI/InputElement/Validators/SlopeValidator.ts diff --git a/assets/layers/cycleways_and_roads/cycleways_and_roads.json b/assets/layers/cycleways_and_roads/cycleways_and_roads.json index ad0af1e8d8..e502f75c3b 100644 --- a/assets/layers/cycleways_and_roads/cycleways_and_roads.json +++ b/assets/layers/cycleways_and_roads/cycleways_and_roads.json @@ -837,6 +837,41 @@ }, "id": "Cycleway:surface" }, + { + "id": "incline", + "question": { + "en": "Does {title()} have an incline?" + }, + "render": { + "en": "This road has an slope of {incline}" + }, + "freeform": { + "key": "incline", + "type": "slope" + }, + "mappings": [ + { + "if": "incline=", + "then": { + "en": "There is (probably) no incline here" + }, + "hideInAnswer": true + }, + { + "if": { + "or": [ + "incline=up", + "incline=down", + "incline=yes" + ] + }, + "then": { + "en": "This road has a slope" + }, + "hideInAnswer": true + } + ] + }, { "question": { "en": "What is the smoothness of this cycleway?", diff --git a/langs/en.json b/langs/en.json index 3bbf5de032..df4b0575d1 100644 --- a/langs/en.json +++ b/langs/en.json @@ -53,6 +53,8 @@ "favouritePoi": { "button": { "isFavourite": "This location is currently marked as favourite and will show up on all thematic maps of MapComplete you visit.", + "isMarkedShort": "Marked as favourite location", + "isNotMarkedShort": "Not marked as favourite", "markAsFavouriteTitle": "Mark this location as favourite location", "markDescription": "Add this location to a personal list of your favourites", "unmark": "Remove from your personal list of favourites", @@ -172,12 +174,14 @@ "openIssueTracker": "File a bug", "openMapillary": "Open Mapillary here", "openOsmcha": "See latest edits made with {theme}", + "seeOnMapillary": "See this image on Mapillary", "themeBy": "Theme maintained by {author}", "title": "Copyright and attribution", "translatedBy": "MapComplete has been translated by {contributors} and {hiddenCount} more contributors" }, "back": "Back", "backToIndex": "Go back to the overview with all thematic maps", + "backToMap": "Back to the map", "backgroundMap": "Select a background layer", "backgroundSwitch": "Switch background", "cancel": "Cancel", @@ -224,6 +228,14 @@ "histogram": { "error_loading": "Could not load the histogram" }, + "labels": { + "background": "Change background", + "filter": "Filter data", + "jumpToLocation": "Go to your current location", + "menu": "Menu", + "zoomIn": "Zoom in", + "zoomOut": "Zoom out" + }, "layerSelection": { "title": "Select layers", "zoomInToSeeThisLayer": "Zoom in to see this layer" @@ -324,6 +336,7 @@ "searchShort": "Search…", "searching": "Searching…" }, + "share": "Share", "sharescreen": { "copiedToClipboard": "Link copied to clipboard", "documentation": "For more information on available URL-parameters, consult the documentation", @@ -679,6 +692,10 @@ "description": "a positive, whole number", "noZero": "Zero is not allowed" }, + "slope": { + "inputExplanation": "Place your phone on the ground with the top side of your phone pointing towards the top of the slope.", + "inputIncorrect": "For correct measurements, make sure the arrow is within the green area." + }, "string": { "description": "a piece of text" }, diff --git a/src/UI/InputElement/Helpers/SlopeInput.svelte b/src/UI/InputElement/Helpers/SlopeInput.svelte new file mode 100644 index 0000000000..e69de29bb2 diff --git a/src/UI/InputElement/InputHelpers.ts b/src/UI/InputElement/InputHelpers.ts index e749e55cd7..8c0fe1785d 100644 --- a/src/UI/InputElement/InputHelpers.ts +++ b/src/UI/InputElement/InputHelpers.ts @@ -1,19 +1,12 @@ -import { ValidatorType } from "./Validators" import { UIEventSource } from "../../Logic/UIEventSource" import { MapProperties } from "../../Models/MapProperties" -import BaseUIElement from "../BaseUIElement" import WikidataSearchBox from "../Wikipedia/WikidataSearchBox" import Wikidata from "../../Logic/Web/Wikidata" import { Utils } from "../../Utils" import Locale from "../i18n/Locale" import { Feature } from "geojson" import { GeoOperations } from "../../Logic/GeoOperations" -import OpeningHoursInput from "./Helpers/OpeningHoursInput.svelte" -import SvelteUIElement from "../Base/SvelteUIElement" -import DirectionInput from "./Helpers/DirectionInput.svelte" -import DateInput from "./Helpers/DateInput.svelte" -import ColorInput from "./Helpers/ColorInput.svelte" export interface InputHelperProperties { /** diff --git a/src/UI/InputElement/Validators/SlopeValidator.ts b/src/UI/InputElement/Validators/SlopeValidator.ts new file mode 100644 index 0000000000..fa3559cff4 --- /dev/null +++ b/src/UI/InputElement/Validators/SlopeValidator.ts @@ -0,0 +1,13 @@ +import NatValidator from "./NatValidator" + +export default class SlopeValidator extends NatValidator { + constructor() { + super("slope", "Validates that the slope is a valid number") + } + isValid(str: string): boolean { + if (str.endsWith("%") || str.endsWith("°")) { + str = str.substring(0, str.length - 1) + } + return super.isValid(str) + } +}