Add check: a preset for a newly created point should match the layer + fix bugs in themes

This commit is contained in:
pietervdvn 2022-02-14 15:40:38 +01:00
parent 3398c9f405
commit c874afc745
5 changed files with 32 additions and 22 deletions

View file

@ -10,6 +10,7 @@ import {TagRenderingConfigJson} from "../Json/TagRenderingConfigJson";
import {TagUtils} from "../../../Logic/Tags/TagUtils";
import {ExtractImages} from "./FixImages";
import ScriptUtils from "../../../scripts/ScriptUtils";
import {And} from "../../../Logic/Tags/And";
class ValidateLanguageCompleteness extends DesugaringStep<any> {
@ -339,6 +340,24 @@ export class ValidateLayer extends DesugaringStep<LayerConfigJson> {
new DetectShadowedMappings().convertAll(<TagRenderingConfigJson[]>json.tagRenderings, context + ".tagRenderings")
}
if(json.presets !== undefined){
// Check that a preset will be picked up by the layer itself
const baseTags = TagUtils.Tag( json.source.osmTags)
for (let i = 0; i < json.presets.length; i++){
const preset = json.presets[i];
const tags : {k: string,v: string}[]= new And(preset.tags.map(t => TagUtils.Tag(t))).asChange({id:"node/-1"})
const properties = {}
for (const tag of tags) {
properties[tag.k] = tag.v
}
const doMatch = baseTags.matchesProperties(properties)
if(!doMatch){
errors.push(context+".presets["+i+"]: This preset does not match the required tags of this layer. This implies that a newly added point will not show up.\n A newly created point will have properties: "+JSON.stringify(properties)+"\n The required tags are: "+baseTags.asHumanString(false, false, {}))
}
}
}
} catch (e) {
errors.push(e)
}

View file

@ -127,25 +127,6 @@
"de": "Knotenpunkt <strong>{rcn_ref}</strong>"
}
},
"presets": [
{
"title": {
"de": "Knotenpunkt"
},
"tags": [
"network:type=node_network"
]
},
{
"title": {
"de": "Knotenpunkt im Netzwerk Spree-Neiße"
},
"tags": [
"network:type=node_network",
"cycle_network=Knotenpunktwegweisung Spree-Neiße"
]
}
],
"tagRenderings": [
{
"question": {

View file

@ -28,6 +28,7 @@
"it": "Friggitoria",
"hu": "Sültkrumplievő-hely"
},
"=presets": [],
"source": {
"=osmTags": {
"and": [
@ -47,7 +48,8 @@
"builtin": "food",
"override": {
"minzoom": 19,
"filter": null
"filter": null,
"name": null
}
}
]

View file

@ -77,7 +77,8 @@
],
"=filter": {
"sameAs": "nature_reserve_centerpoints"
}
},
"=presets": []
}
},
{
@ -103,6 +104,9 @@
},
"presets": []
}
],
"presets": [
{"tags+": "operator=Natuurpunt"}
]
}
},
@ -193,6 +197,10 @@
"builtin": "birdhide",
"override": {
"minzoom": 14,
"presets": [
{"tags+": "operator=Natuurpunt"},
{"tags+": "operator=Natuurpunt"}
],
"source": {
"geoJson": "https://raw.githubusercontent.com/pietervdvn/MapComplete-data/main/natuurpunt_cache/natuurpunt_{layer}_{z}_{x}_{y}.geojson",
"geoJsonZoomLevel": 12,

View file

@ -139,8 +139,8 @@
"id": "to_handle",
"options": [
{
"question": "Only show non-matched objects",
"default": true,
"question": "Only show non-matched objects",
"osmTags": {
"and": [
"_imported=",