Add filters based on mappigns, use in artwork

This commit is contained in:
Pieter Vander Vennet 2024-04-08 01:58:07 +02:00
parent 8abfcae02f
commit 51c1448de8
4 changed files with 35 additions and 6 deletions

View file

@ -875,8 +875,8 @@
}
],
"filter": [
"has_image"
"has_image",
"artwork-artwork_type"
],
"deletion": {
"softDeletionTags": {

View file

@ -64,11 +64,36 @@ class ExpandFilter extends DesugaringStep<LayerConfigJson> {
}
const newFilters: FilterConfigJson[] = []
for (const filter of <(FilterConfigJson | string)[]>json.filter) {
const filters = <(FilterConfigJson | string)[]>json.filter
for (let i = 0; i < filters.length; i++){
const filter = filters[i]
if (typeof filter !== "string") {
newFilters.push(filter)
continue
}
const matchingTr =<TagRenderingConfigJson> json.tagRenderings.find(tr => tr["id"] === filter)
if(matchingTr){
if(!(matchingTr.mappings?.length >= 1)){
context.enters("filter",i ).err("Found a matching tagRendering to base a filter on, but this tagRendering does not contain any mappings")
}
const options = matchingTr.mappings.map(mapping => ({
question: mapping.then,
osmTags: mapping.if
}))
options.unshift({
question: {
en:"All types"
},
osmTags: undefined
})
newFilters.push({
id: filter,
options
})
continue
}
if (filter.indexOf(".") > 0) {
if (this._state.sharedLayers.size > 0) {
const split = filter.split(".")

View file

@ -432,7 +432,7 @@ export class DetectConflictingAddExtraTags extends DesugaringStep<TagRenderingCo
}
try {
const tagRendering = new TagRenderingConfig(json)
const tagRendering = new TagRenderingConfig(json, context.path.join("."))
for (let i = 0; i < tagRendering.mappings.length; i++) {
const mapping = tagRendering.mappings[i]
@ -632,7 +632,7 @@ export class DetectShadowedMappings extends DesugaringStep<TagRenderingConfigJso
const ifTags = TagUtils.Tag(m.if, c.enter("if"))
const hideInAnswer = m["hideInAnswer"]
if (hideInAnswer !== undefined && hideInAnswer !== false && hideInAnswer !== true) {
let conditionTags = TagUtils.Tag(hideInAnswer)
const conditionTags = TagUtils.Tag(hideInAnswer)
// Merge the condition too!
return new And([conditionTags, ifTags])
}

View file

@ -416,7 +416,11 @@ export interface LayerConfigJson {
/**
* All the extra questions for filtering.
* If a string is given, mapComplete will search in 'filters.json' for the appropriate filter or will try to parse it as `layername.filterid` and us that one
* If a string is given, mapComplete will search in
* 1. The tagrenderings for a match on ID and use the mappings as options
* 2. search 'filters.json' for the appropriate filter or
* 3. will try to parse it as `layername.filterid` and us that one.
*
*
* group: filters
*/