From 0aae923187ee66c12f10a5e3d7b47d42644e806c Mon Sep 17 00:00:00 2001 From: pietervdvn Date: Fri, 22 Apr 2022 16:09:55 +0200 Subject: [PATCH] Add projected_centerpoint as pointrenderingoption --- .../RenderingMultiPlexerFeatureSource.ts | 46 +++++++++++++------ .../Json/PointRenderingConfigJson.ts | 5 +- Models/ThemeConfig/PointRenderingConfig.ts | 4 +- assets/layers/etymology/etymology.json | 28 ++++++++++- assets/layers/tree_node/tree_node.json | 17 +++++-- assets/layers/waste_basket/waste_basket.json | 4 +- .../mapcomplete-changes.json | 42 ++++++----------- langs/layers/en.json | 3 ++ 8 files changed, 96 insertions(+), 53 deletions(-) diff --git a/Logic/FeatureSource/Sources/RenderingMultiPlexerFeatureSource.ts b/Logic/FeatureSource/Sources/RenderingMultiPlexerFeatureSource.ts index 5349d8d431..1f5d8cbb41 100644 --- a/Logic/FeatureSource/Sources/RenderingMultiPlexerFeatureSource.ts +++ b/Logic/FeatureSource/Sources/RenderingMultiPlexerFeatureSource.ts @@ -1,5 +1,5 @@ /** - * This feature source helps the ShowDataLayer class: it introduces the necessary extra features and indiciates with what renderConfig it should be rendered. + * This feature source helps the ShowDataLayer class: it introduces the necessary extra features and indicates with what renderConfig it should be rendered. */ import {UIEventSource} from "../../UIEventSource"; import {GeoOperations} from "../../GeoOperations"; @@ -11,22 +11,25 @@ export default class RenderingMultiPlexerFeatureSource { public readonly features: UIEventSource<(any & { pointRenderingIndex: number | undefined, lineRenderingIndex: number | undefined })[]>; constructor(upstream: FeatureSource, layer: LayerConfig) { + + const pointRenderObjects: { rendering: PointRenderingConfig, index: number }[] = layer.mapRendering.map((r, i) => ({ + rendering: r, + index: i + })) + const pointRenderings = pointRenderObjects.filter(r => r.rendering.location.has("point")) + const centroidRenderings = pointRenderObjects.filter(r => r.rendering.location.has("centroid")) + const projectedCentroidRenderings = pointRenderObjects.filter(r => r.rendering.location.has("projected_centerpoint")) + const startRenderings = pointRenderObjects.filter(r => r.rendering.location.has("start")) + const endRenderings = pointRenderObjects.filter(r => r.rendering.location.has("end")) + const hasCentroid = centroidRenderings.length > 0 || projectedCentroidRenderings.length > 0 + const lineRenderObjects = layer.lineRendering + this.features = upstream.features.map( features => { if (features === undefined) { return; } - const pointRenderObjects: { rendering: PointRenderingConfig, index: number }[] = layer.mapRendering.map((r, i) => ({ - rendering: r, - index: i - })) - const pointRenderings = pointRenderObjects.filter(r => r.rendering.location.has("point")) - const centroidRenderings = pointRenderObjects.filter(r => r.rendering.location.has("centroid")) - const startRenderings = pointRenderObjects.filter(r => r.rendering.location.has("start")) - const endRenderings = pointRenderObjects.filter(r => r.rendering.location.has("end")) - - const lineRenderObjects = layer.lineRendering const withIndex: (any & { pointRenderingIndex: number | undefined, lineRenderingIndex: number | undefined, multiLineStringIndex: number | undefined })[] = []; @@ -55,12 +58,25 @@ export default class RenderingMultiPlexerFeatureSource { } } else { // This is a a line: add the centroids - for (const rendering of centroidRenderings) { - addAsPoint(feat, rendering, GeoOperations.centerpointCoordinates(feat)) + let centerpoint: [number, number] = undefined; + let projectedCenterPoint : [number, number] = undefined + if(hasCentroid){ + centerpoint = GeoOperations.centerpointCoordinates(feat) + if(projectedCentroidRenderings.length > 0){ + projectedCenterPoint = <[number,number]> GeoOperations.nearestPoint(feat, centerpoint).geometry.coordinates + } } + for (const rendering of centroidRenderings) { + addAsPoint(feat, rendering, centerpoint) + } + if (feat.geometry.type === "LineString") { + for (const rendering of projectedCentroidRenderings) { + addAsPoint(feat, rendering, projectedCenterPoint) + } + // Add start- and endpoints const coordinates = feat.geometry.coordinates for (const rendering of startRenderings) { @@ -71,6 +87,10 @@ export default class RenderingMultiPlexerFeatureSource { addAsPoint(feat, rendering, coordinate) } + }else{ + for (const rendering of projectedCentroidRenderings) { + addAsPoint(feat, rendering, centerpoint) + } } // AT last, add it 'as is' to what we should render diff --git a/Models/ThemeConfig/Json/PointRenderingConfigJson.ts b/Models/ThemeConfig/Json/PointRenderingConfigJson.ts index 5170f89534..c9a4abc9d1 100644 --- a/Models/ThemeConfig/Json/PointRenderingConfigJson.ts +++ b/Models/ThemeConfig/Json/PointRenderingConfigJson.ts @@ -13,9 +13,10 @@ export default interface PointRenderingConfigJson { /** * All the locations that this point should be rendered at. - * Using `location: ["point", "centroid"] will always render centerpoint + * Using `location: ["point", "centroid"] will always render centerpoint. + * 'projected_centerpoint' will show an item on the line itself, near the middle of the line. (LineStrings only) */ - location: ("point" | "centroid" | "start" | "end" | string)[] + location: ("point" | "centroid" | "start" | "end" | "projected_centerpoint" | string)[] /** * The icon for an element. diff --git a/Models/ThemeConfig/PointRenderingConfig.ts b/Models/ThemeConfig/PointRenderingConfig.ts index 0a02149b84..39dcec1563 100644 --- a/Models/ThemeConfig/PointRenderingConfig.ts +++ b/Models/ThemeConfig/PointRenderingConfig.ts @@ -15,8 +15,8 @@ import {VariableUiElement} from "../../UI/Base/VariableUIElement"; export default class PointRenderingConfig extends WithContextLoader { - private static readonly allowed_location_codes = new Set(["point", "centroid", "start", "end"]) - public readonly location: Set<"point" | "centroid" | "start" | "end" | string> + private static readonly allowed_location_codes = new Set(["point", "centroid", "start", "end","projected_centerpoint"]) + public readonly location: Set<"point" | "centroid" | "start" | "end" | "projected_centerpoint" | string> public readonly icon: TagRenderingConfig; public readonly iconBadges: { if: TagsFilter; then: TagRenderingConfig }[]; diff --git a/assets/layers/etymology/etymology.json b/assets/layers/etymology/etymology.json index 1447c7d812..de0b63aabb 100644 --- a/assets/layers/etymology/etymology.json +++ b/assets/layers/etymology/etymology.json @@ -52,7 +52,10 @@ "helperArgs": [ "name", { - "notInstanceOf": ["Q79007","Q22698"], + "notInstanceOf": [ + "Q79007", + "Q22698" + ], "removePostfixes": [ "steenweg", "heirbaan", @@ -205,6 +208,29 @@ } ] } + }, + { + "location": [ + "projected_centerpoint" + ], + "label": "
LABEL
", + "icon": { + "render": "pin:#05d7fcaa", + "mappings": [ + { + "if": { + "and": [ + "name:etymology=", + "name:etymology:wikidata=" + ] + }, + "then": "pin:#fcca05aa" + } + ] + }, + "iconSize": { + "render": "40,40,center" + } } ] } \ No newline at end of file diff --git a/assets/layers/tree_node/tree_node.json b/assets/layers/tree_node/tree_node.json index 3035cc7ef0..4dd324cf1f 100644 --- a/assets/layers/tree_node/tree_node.json +++ b/assets/layers/tree_node/tree_node.json @@ -320,7 +320,7 @@ "en": "What species is this tree?" }, "render": { - "*":"{wikipedia(species:wikidata):max-height: 25rem}" + "*": "{wikipedia(species:wikidata):max-height: 25rem}" }, "freeform": { "key": "species:wikidata", @@ -328,18 +328,25 @@ "helperArgs": [ "species", { - "instanceOf": [10884, 16521] - }] + "instanceOf": [ + 10884, + 16521 + ] + } + ] } }, { "id": "tree-wikipedia", "#": "If this tree has a wikipedia article, show it. People can _only_ set the species though!", "render": { - "*":"{wikipedia()}" + "*": "{wikipedia()}" }, "condition": { - "or": ["wikipedia~*","wikidata~*"] + "or": [ + "wikipedia~*", + "wikidata~*" + ] } }, { diff --git a/assets/layers/waste_basket/waste_basket.json b/assets/layers/waste_basket/waste_basket.json index 88a369908e..67d9687021 100644 --- a/assets/layers/waste_basket/waste_basket.json +++ b/assets/layers/waste_basket/waste_basket.json @@ -31,7 +31,7 @@ "de": "Dies ist ein öffentlicher Abfalleimer, in den Sie Ihren Müll entsorgen können." }, "tagRenderings": [ - "images", + "images", { "id": "waste-basket-waste-types", "question": { @@ -294,4 +294,4 @@ } } ] -} +} \ No newline at end of file diff --git a/assets/themes/mapcomplete-changes/mapcomplete-changes.json b/assets/themes/mapcomplete-changes/mapcomplete-changes.json index 2f479a092b..c90abd4c4d 100644 --- a/assets/themes/mapcomplete-changes/mapcomplete-changes.json +++ b/assets/themes/mapcomplete-changes/mapcomplete-changes.json @@ -1,16 +1,13 @@ { "id": "mapcomplete-changes", "title": { - "en": "Changes made with MapComplete", - "de": "Änderungen mit MapComplete" + "en": "Changes made with MapComplete" }, "shortDescription": { - "en": "Shows changes made by MapComplete", - "de": "Zeigt Änderungen von MapComplete" + "en": "Shows changes made by MapComplete" }, "description": { - "en": "This maps shows all the changes made with MapComplete", - "de": "Diese Karte zeigt alle Änderungen die mit MapComplete gemacht wurden" + "en": "This maps shows all the changes made with MapComplete" }, "maintainer": "", "icon": "./assets/svg/logo.svg", @@ -25,8 +22,7 @@ { "id": "mapcomplete-changes", "name": { - "en": "Changeset centers", - "de": "Schwerpunkte von Änderungssätzen" + "en": "Changeset centers" }, "minzoom": 0, "source": { @@ -40,41 +36,35 @@ ], "title": { "render": { - "en": "Changeset for {theme}", - "de": "Änderungen für {theme}" + "en": "Changeset for {theme}" } }, "description": { - "en": "Shows all MapComplete changes", - "de": "Zeigt alle MapComplete Änderungen" + "en": "Shows all MapComplete changes" }, "tagRenderings": [ { "id": "render_id", "render": { - "en": "Changeset {id}", - "de": "Änderung {id}" + "en": "Changeset {id}" } }, { "id": "contributor", "render": { - "en": "Change made by {_last_edit:contributor}", - "de": "Änderung wurde von {_last_edit:contributor} gemacht" + "en": "Change made by {_last_edit:contributor}" } }, { "id": "theme", "render": { - "en": "Change with theme {theme}", - "de": "Änderung mit Thema {theme}" + "en": "Change with theme {theme}" }, "mappings": [ { "if": "theme~http.*", "then": { - "en": "Change with unofficial theme {theme}", - "de": "Änderung mit inoffiziellem Thema {theme}" + "en": "Change with unofficial theme {theme}" } } ] @@ -338,8 +328,7 @@ } ], "question": { - "en": "Themename contains {search}", - "de": "Themenname enthält {search}" + "en": "Themename contains {search}" } } ] @@ -355,8 +344,7 @@ } ], "question": { - "en": "Made by contributor {search}", - "de": "Erstellt von {search}" + "en": "Made by contributor {search}" } } ] @@ -372,8 +360,7 @@ } ], "question": { - "en": "Not made by contributor {search}", - "de": "Nicht erstellt von {search}" + "en": "Not made by contributor {search}" } } ] @@ -388,8 +375,7 @@ { "id": "link_to_more", "render": { - "en": "More statistics can be found here", - "de": "Weitere Statistiken finden Sie hier" + "en": "More statistics can be found here" } }, { diff --git a/langs/layers/en.json b/langs/layers/en.json index 574c793046..3810cd4645 100644 --- a/langs/layers/en.json +++ b/langs/layers/en.json @@ -5454,6 +5454,9 @@ }, "question": "Is this a broadleaved or needleleaved tree?" }, + "tree-species-wikidata": { + "question": "What species is this tree?" + }, "tree_node-name": { "mappings": { "0": {