From e0b58a0f554772aa639d62fa4860fd280d74cb15 Mon Sep 17 00:00:00 2001 From: pietervdvn Date: Mon, 10 Jan 2022 19:10:13 +0100 Subject: [PATCH] Import work --- UI/Popup/ImportButton.ts | 15 ++++-- assets/layers/note_import/note_import.json | 54 ++++++++++++++++++++++ assets/themes/bookcases/bookcases.json | 3 +- 3 files changed, 68 insertions(+), 4 deletions(-) create mode 100644 assets/layers/note_import/note_import.json diff --git a/UI/Popup/ImportButton.ts b/UI/Popup/ImportButton.ts index 9b587c09e4..77d13427f4 100644 --- a/UI/Popup/ImportButton.ts +++ b/UI/Popup/ImportButton.ts @@ -37,6 +37,7 @@ import TagApplyButton from "./TagApplyButton"; import LayerConfig from "../../Models/ThemeConfig/LayerConfig"; import * as conflation_json from "../../assets/layers/conflation/conflation.json"; import {GeoOperations} from "../../Logic/GeoOperations"; +import {Or} from "../../Logic/Tags/Or"; abstract class AbstractImportButton implements SpecialVisualizations { @@ -56,7 +57,7 @@ It is only functional in official themes, but can be tested in unoffical themes. #### Specifying which tags to copy or add -The argument \`tags\` of the import button takes a \`;\`-seperated list of tags to add. +The argument \`tags\` of the import button takes a \`;\`-seperated list of tags to add (or the name of a property which contains a JSON-list of properties). ${Utils.Special_visualizations_tagsToApplyHelpText} ${Utils.special_visualizations_importRequirementDocs} @@ -68,7 +69,7 @@ ${Utils.special_visualizations_importRequirementDocs} }, { name: "tags", - doc: "The tags to add onto the new object - see specification above" + doc: "The tags to add onto the new object - see specification above. If this is a key (a single word occuring in the properties of the object), the corresponding value is taken and expanded instead" }, { name: "text", @@ -201,7 +202,15 @@ ${Utils.special_visualizations_importRequirementDocs} private parseArgs(argsRaw: string[], originalFeatureTags: UIEventSource): { minzoom: string, max_snap_distance: string, snap_onto_layers: string, icon: string, text: string, tags: string, targetLayer: string, newTags: UIEventSource } { const baseArgs = Utils.ParseVisArgs(this.args, argsRaw) if (originalFeatureTags !== undefined) { - baseArgs["newTags"] = TagApplyButton.generateTagsToApply(baseArgs.tags, originalFeatureTags) + + const tags = baseArgs.tags + if(tags.indexOf(" ") < 0 && tags.indexOf(";") < 0){ + // This might be a propertie to expand... + const items : string = originalFeatureTags.data[tags] + baseArgs["newTags"] = TagApplyButton.generateTagsToApply(items, originalFeatureTags) + }else{ + baseArgs["newTags"] = TagApplyButton.generateTagsToApply(tags, originalFeatureTags) + } } return baseArgs } diff --git a/assets/layers/note_import/note_import.json b/assets/layers/note_import/note_import.json new file mode 100644 index 0000000000..3640f252eb --- /dev/null +++ b/assets/layers/note_import/note_import.json @@ -0,0 +1,54 @@ +{ + "id": "note_import", + "description": "Te template for note note imports.", + "source": { + "osmTags": { + "and": ["id~*" + ] + }, + "geoJson": "https://api.openstreetmap.org/api/0.6/notes.json?closed=7&bbox={x_min},{y_min},{x_max},{y_max}", + "geoJsonZoomLevel": 12, + "maxCacheAge": 0 + }, + "minzoom": 10, + "title": { + "render": { + "en": "Possible feature" + } + }, + "calculatedTags": [ + "_first_comment:=feat.get('comments')[0].text.toLowerCase()", + "_is_import_comment:=(() => {const parsed = feat.properties._first_comment.match('\\(.*\\)https:\\/\\/mapcomplete\\.osm\\.be\\/\\([a-zA-Z0-9_-]*\\)[^\\n]*}')()" + ], + "titleIcons": [ + { + "render": "" + } + ], + "tagRenderings": [ + { + "id": "conversation", + "render": "{visualize_note_comments()}" + }, + { + "id": "add_image", + "render": "{add_image_to_note()}" + }, + { + "id": "comment", + "render": "{add_note_comment()}" + } + ], + "mapRendering": [ + { + "location": [ + "point", + "centroid" + ], + "icon": { + "render": "teardrop:#3333cc" + }, + "iconSize": "40,40,bottom" + } + ] +} \ No newline at end of file diff --git a/assets/themes/bookcases/bookcases.json b/assets/themes/bookcases/bookcases.json index 252f510485..5dfc454ad8 100644 --- a/assets/themes/bookcases/bookcases.json +++ b/assets/themes/bookcases/bookcases.json @@ -43,6 +43,7 @@ "startZoom": 1, "widenFactor": 1, "layers": [ - "public_bookcase" + "public_bookcase", + "note_import" ] } \ No newline at end of file