Add projected_centerpoint as pointrenderingoption

This commit is contained in:
Pieter Vander Vennet 2022-04-22 16:09:55 +02:00
parent 0c31e885e3
commit 0aae923187
8 changed files with 96 additions and 53 deletions

View file

@ -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 {UIEventSource} from "../../UIEventSource";
import {GeoOperations} from "../../GeoOperations"; import {GeoOperations} from "../../GeoOperations";
@ -11,22 +11,25 @@ export default class RenderingMultiPlexerFeatureSource {
public readonly features: UIEventSource<(any & { pointRenderingIndex: number | undefined, lineRenderingIndex: number | undefined })[]>; public readonly features: UIEventSource<(any & { pointRenderingIndex: number | undefined, lineRenderingIndex: number | undefined })[]>;
constructor(upstream: FeatureSource, layer: LayerConfig) { 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( this.features = upstream.features.map(
features => { features => {
if (features === undefined) { if (features === undefined) {
return; 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 })[] = []; const withIndex: (any & { pointRenderingIndex: number | undefined, lineRenderingIndex: number | undefined, multiLineStringIndex: number | undefined })[] = [];
@ -55,12 +58,25 @@ export default class RenderingMultiPlexerFeatureSource {
} }
} else { } else {
// This is a a line: add the centroids // This is a a line: add the centroids
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) { for (const rendering of centroidRenderings) {
addAsPoint(feat, rendering, GeoOperations.centerpointCoordinates(feat)) addAsPoint(feat, rendering, centerpoint)
} }
if (feat.geometry.type === "LineString") { if (feat.geometry.type === "LineString") {
for (const rendering of projectedCentroidRenderings) {
addAsPoint(feat, rendering, projectedCenterPoint)
}
// Add start- and endpoints // Add start- and endpoints
const coordinates = feat.geometry.coordinates const coordinates = feat.geometry.coordinates
for (const rendering of startRenderings) { for (const rendering of startRenderings) {
@ -71,6 +87,10 @@ export default class RenderingMultiPlexerFeatureSource {
addAsPoint(feat, rendering, coordinate) 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 // AT last, add it 'as is' to what we should render

View file

@ -13,9 +13,10 @@ export default interface PointRenderingConfigJson {
/** /**
* All the locations that this point should be rendered at. * 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. * The icon for an element.

View file

@ -15,8 +15,8 @@ import {VariableUiElement} from "../../UI/Base/VariableUIElement";
export default class PointRenderingConfig extends WithContextLoader { export default class PointRenderingConfig extends WithContextLoader {
private static readonly allowed_location_codes = new Set<string>(["point", "centroid", "start", "end"]) private static readonly allowed_location_codes = new Set<string>(["point", "centroid", "start", "end","projected_centerpoint"])
public readonly location: Set<"point" | "centroid" | "start" | "end" | string> public readonly location: Set<"point" | "centroid" | "start" | "end" | "projected_centerpoint" | string>
public readonly icon: TagRenderingConfig; public readonly icon: TagRenderingConfig;
public readonly iconBadges: { if: TagsFilter; then: TagRenderingConfig }[]; public readonly iconBadges: { if: TagsFilter; then: TagRenderingConfig }[];

View file

@ -52,7 +52,10 @@
"helperArgs": [ "helperArgs": [
"name", "name",
{ {
"notInstanceOf": ["Q79007","Q22698"], "notInstanceOf": [
"Q79007",
"Q22698"
],
"removePostfixes": [ "removePostfixes": [
"steenweg", "steenweg",
"heirbaan", "heirbaan",
@ -205,6 +208,29 @@
} }
] ]
} }
},
{
"location": [
"projected_centerpoint"
],
"label": "<div class='bg-white rounded-full p-x-2'>LABEL</div>",
"icon": {
"render": "pin:#05d7fcaa",
"mappings": [
{
"if": {
"and": [
"name:etymology=",
"name:etymology:wikidata="
]
},
"then": "pin:#fcca05aa"
}
]
},
"iconSize": {
"render": "40,40,center"
}
} }
] ]
} }

View file

@ -320,7 +320,7 @@
"en": "What species is this tree?" "en": "What species is this tree?"
}, },
"render": { "render": {
"*":"{wikipedia(species:wikidata):max-height: 25rem}" "*": "{wikipedia(species:wikidata):max-height: 25rem}"
}, },
"freeform": { "freeform": {
"key": "species:wikidata", "key": "species:wikidata",
@ -328,18 +328,25 @@
"helperArgs": [ "helperArgs": [
"species", "species",
{ {
"instanceOf": [10884, 16521] "instanceOf": [
}] 10884,
16521
]
}
]
} }
}, },
{ {
"id": "tree-wikipedia", "id": "tree-wikipedia",
"#": "If this tree has a wikipedia article, show it. People can _only_ set the species though!", "#": "If this tree has a wikipedia article, show it. People can _only_ set the species though!",
"render": { "render": {
"*":"{wikipedia()}" "*": "{wikipedia()}"
}, },
"condition": { "condition": {
"or": ["wikipedia~*","wikidata~*"] "or": [
"wikipedia~*",
"wikidata~*"
]
} }
}, },
{ {

View file

@ -31,7 +31,7 @@
"de": "Dies ist ein öffentlicher Abfalleimer, in den Sie Ihren Müll entsorgen können." "de": "Dies ist ein öffentlicher Abfalleimer, in den Sie Ihren Müll entsorgen können."
}, },
"tagRenderings": [ "tagRenderings": [
"images", "images",
{ {
"id": "waste-basket-waste-types", "id": "waste-basket-waste-types",
"question": { "question": {

View file

@ -1,16 +1,13 @@
{ {
"id": "mapcomplete-changes", "id": "mapcomplete-changes",
"title": { "title": {
"en": "Changes made with MapComplete", "en": "Changes made with MapComplete"
"de": "Änderungen mit MapComplete"
}, },
"shortDescription": { "shortDescription": {
"en": "Shows changes made by MapComplete", "en": "Shows changes made by MapComplete"
"de": "Zeigt Änderungen von MapComplete"
}, },
"description": { "description": {
"en": "This maps shows all the changes made with MapComplete", "en": "This maps shows all the changes made with MapComplete"
"de": "Diese Karte zeigt alle Änderungen die mit MapComplete gemacht wurden"
}, },
"maintainer": "", "maintainer": "",
"icon": "./assets/svg/logo.svg", "icon": "./assets/svg/logo.svg",
@ -25,8 +22,7 @@
{ {
"id": "mapcomplete-changes", "id": "mapcomplete-changes",
"name": { "name": {
"en": "Changeset centers", "en": "Changeset centers"
"de": "Schwerpunkte von Änderungssätzen"
}, },
"minzoom": 0, "minzoom": 0,
"source": { "source": {
@ -40,41 +36,35 @@
], ],
"title": { "title": {
"render": { "render": {
"en": "Changeset for {theme}", "en": "Changeset for {theme}"
"de": "Änderungen für {theme}"
} }
}, },
"description": { "description": {
"en": "Shows all MapComplete changes", "en": "Shows all MapComplete changes"
"de": "Zeigt alle MapComplete Änderungen"
}, },
"tagRenderings": [ "tagRenderings": [
{ {
"id": "render_id", "id": "render_id",
"render": { "render": {
"en": "Changeset <a href='https://openstreetmap.org/changeset/{id}' target='_blank'>{id}</a>", "en": "Changeset <a href='https://openstreetmap.org/changeset/{id}' target='_blank'>{id}</a>"
"de": "Änderung <a href='https://openstreetmap.org/changeset/{id}' target='_blank'>{id}</a>"
} }
}, },
{ {
"id": "contributor", "id": "contributor",
"render": { "render": {
"en": "Change made by <a href='https://openstreetmap.org/user/{_last_edit:contributor}' target='_blank'>{_last_edit:contributor}</a>", "en": "Change made by <a href='https://openstreetmap.org/user/{_last_edit:contributor}' target='_blank'>{_last_edit:contributor}</a>"
"de": "Änderung wurde von <a href='https://openstreetmap.org/user/{_last_edit:contributor}' target='_blank'>{_last_edit:contributor}</a> gemacht"
} }
}, },
{ {
"id": "theme", "id": "theme",
"render": { "render": {
"en": "Change with theme <a href='https://mapcomplete.osm.be/{theme}'>{theme}</a>", "en": "Change with theme <a href='https://mapcomplete.osm.be/{theme}'>{theme}</a>"
"de": "Änderung mit Thema <a href='https://mapcomplete.osm.be/{theme}'>{theme}</a>"
}, },
"mappings": [ "mappings": [
{ {
"if": "theme~http.*", "if": "theme~http.*",
"then": { "then": {
"en": "Change with <b>unofficial</b> theme <a href='https://mapcomplete.osm.be/theme.html?userlayout={theme}'>{theme}</a>", "en": "Change with <b>unofficial</b> theme <a href='https://mapcomplete.osm.be/theme.html?userlayout={theme}'>{theme}</a>"
"de": "Änderung mit <b>inoffiziellem</b> Thema <a href='https://mapcomplete.osm.be/theme.html?userlayout={theme}'>{theme}</a>"
} }
} }
] ]
@ -338,8 +328,7 @@
} }
], ],
"question": { "question": {
"en": "Themename contains {search}", "en": "Themename contains {search}"
"de": "Themenname enthält {search}"
} }
} }
] ]
@ -355,8 +344,7 @@
} }
], ],
"question": { "question": {
"en": "Made by contributor {search}", "en": "Made by contributor {search}"
"de": "Erstellt von {search}"
} }
} }
] ]
@ -372,8 +360,7 @@
} }
], ],
"question": { "question": {
"en": "<b>Not</b> made by contributor {search}", "en": "<b>Not</b> made by contributor {search}"
"de": "<b>Nicht</b> erstellt von {search}"
} }
} }
] ]
@ -388,8 +375,7 @@
{ {
"id": "link_to_more", "id": "link_to_more",
"render": { "render": {
"en": "More statistics can be found <a href='https://github.com/pietervdvn/MapComplete/tree/develop/Docs/Tools/graphs' target='_blank'>here</a>", "en": "More statistics can be found <a href='https://github.com/pietervdvn/MapComplete/tree/develop/Docs/Tools/graphs' target='_blank'>here</a>"
"de": "Weitere Statistiken finden Sie <a href='https://github.com/pietervdvn/MapComplete/tree/develop/Docs/Tools/graphs' target='_blank'>hier</a>"
} }
}, },
{ {

View file

@ -5454,6 +5454,9 @@
}, },
"question": "Is this a broadleaved or needleleaved tree?" "question": "Is this a broadleaved or needleleaved tree?"
}, },
"tree-species-wikidata": {
"question": "What species is this tree?"
},
"tree_node-name": { "tree_node-name": {
"mappings": { "mappings": {
"0": { "0": {