forked from MapComplete/MapComplete
Themes: allow to disable auto filters
This commit is contained in:
parent
c591770eab
commit
b3492930b8
5 changed files with 37 additions and 32 deletions
|
@ -201,6 +201,7 @@
|
|||
]
|
||||
}
|
||||
},
|
||||
"filter": null,
|
||||
"=presets": []
|
||||
}
|
||||
},
|
||||
|
|
|
@ -7,7 +7,7 @@ export class AllSharedLayers {
|
|||
public static sharedLayers: Map<string, LayerConfig> = AllSharedLayers.getSharedLayers()
|
||||
public static getSharedLayersConfigs(): Map<string, LayerConfigJson> {
|
||||
const sharedLayers = new Map<string, LayerConfigJson>()
|
||||
for (const layer of known_layers.layers) {
|
||||
for (const layer of known_layers["layers"]) {
|
||||
// @ts-ignore
|
||||
sharedLayers.set(layer.id, layer)
|
||||
}
|
||||
|
@ -16,7 +16,7 @@ export class AllSharedLayers {
|
|||
}
|
||||
private static getSharedLayers(): Map<string, LayerConfig> {
|
||||
const sharedLayers = new Map<string, LayerConfig>()
|
||||
for (const layer of known_layers.layers) {
|
||||
for (const layer of known_layers["layers"]) {
|
||||
try {
|
||||
// @ts-ignore
|
||||
const parsed = new LayerConfig(layer, "shared_layers")
|
||||
|
|
|
@ -39,7 +39,8 @@ class ExpandFilter extends DesugaringStep<LayerConfigJson> {
|
|||
constructor(state: DesugaringContext) {
|
||||
super(
|
||||
["Expands filters: replaces a shorthand by the value found in 'filters.json'.",
|
||||
"If the string is formatted 'layername.filtername, it will be looked up into that layer instead. If a tagRendering sets 'filter', this filter will also be included",
|
||||
"If the string is formatted 'layername.filtername, it will be looked up into that layer instead.",
|
||||
"If a tagRendering sets 'filter', this filter will also be included - unless \"#filter\":\"no-auto\" is set",
|
||||
""].join(" "),
|
||||
["filter"],
|
||||
"ExpandFilter",
|
||||
|
@ -96,6 +97,8 @@ class ExpandFilter extends DesugaringStep<LayerConfigJson> {
|
|||
return json // Nothing to change here
|
||||
}
|
||||
|
||||
const noAutoFilters = json["#filter"] === "no-auto"
|
||||
|
||||
const newFilters: FilterConfigJson[] = []
|
||||
const filters = <(FilterConfigJson | string)[]>json.filter
|
||||
|
||||
|
@ -109,34 +112,36 @@ class ExpandFilter extends DesugaringStep<LayerConfigJson> {
|
|||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks all tagRendering. If a tagrendering has 'filter' set, add this filter to the layer config
|
||||
*/
|
||||
for (let i = 0; i < json.tagRenderings?.length; i++) {
|
||||
const tagRendering = <TagRenderingConfigJson>json.tagRenderings[i]
|
||||
if (!tagRendering?.filter) {
|
||||
continue
|
||||
}
|
||||
if (tagRendering.filter === true) {
|
||||
if (filterExists(tagRendering["id"])) {
|
||||
if (!noAutoFilters){
|
||||
/**
|
||||
* Checks all tagRendering. If a tagrendering has 'filter' set, add this filter to the layer config
|
||||
*/
|
||||
for (let i = 0; i < json.tagRenderings?.length; i++) {
|
||||
const tagRendering = <TagRenderingConfigJson>json.tagRenderings[i]
|
||||
if (!tagRendering?.filter) {
|
||||
continue
|
||||
}
|
||||
filters.push(ExpandFilter.buildFilterFromTagRendering(tagRendering, context.enters("tagRenderings", i, "filter")))
|
||||
continue
|
||||
}
|
||||
for (const filterName of tagRendering.filter ?? []) {
|
||||
if (typeof filterName !== "string") {
|
||||
context.enters("tagRenderings", i, "filter").err("Not a string: " + filterName)
|
||||
}
|
||||
if (filterExists(filterName)) {
|
||||
// This filter has already been added
|
||||
if (tagRendering.filter === true) {
|
||||
if (filterExists(tagRendering["id"])) {
|
||||
continue
|
||||
}
|
||||
filters.push(ExpandFilter.buildFilterFromTagRendering(tagRendering, context.enters("tagRenderings", i, "filter")))
|
||||
continue
|
||||
}
|
||||
if (!filterName) {
|
||||
context.err("Got undefined as filter expansion in " + tagRendering["id"])
|
||||
continue
|
||||
for (const filterName of tagRendering.filter ?? []) {
|
||||
if (typeof filterName !== "string") {
|
||||
context.enters("tagRenderings", i, "filter").err("Not a string: " + filterName)
|
||||
}
|
||||
if (filterExists(filterName)) {
|
||||
// This filter has already been added
|
||||
continue
|
||||
}
|
||||
if (!filterName) {
|
||||
context.err("Got undefined as filter expansion in " + tagRendering["id"])
|
||||
continue
|
||||
}
|
||||
filters.push(filterName)
|
||||
}
|
||||
filters.push(filterName)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -442,6 +442,7 @@ export interface LayerConfigJson {
|
|||
* 2. search 'filters.json' for the appropriate filter or
|
||||
* 3. will try to parse it as `layername.filterid` and us that one.
|
||||
*
|
||||
* Note: adding "#filter":"no-auto" will disable the filters added by tagRenderings
|
||||
*
|
||||
* group: filters
|
||||
*/
|
||||
|
|
|
@ -8,12 +8,13 @@
|
|||
import FilterToggle from "./FilterToggle.svelte"
|
||||
import ToSvelte from "../Base/ToSvelte.svelte"
|
||||
import Tr from "../Base/Tr.svelte"
|
||||
import Constants from "../../Models/Constants"
|
||||
import { Store } from "../../Logic/UIEventSource"
|
||||
import Translations from "../i18n/Translations"
|
||||
|
||||
export let activeFilters: ActiveFilter[]
|
||||
export let state: SpecialVisualizationState
|
||||
let loading = false
|
||||
const t =Translations.t.general.search
|
||||
|
||||
|
||||
let activeLayers: Store<FilteredLayer[]> = state.layerState.activeLayers.mapD(l => l.filter(l => l.layerDef.isNormal()))
|
||||
|
@ -42,10 +43,10 @@
|
|||
{#if activeFilters.length > 0 || $activeLayers.length === 1 || $nonactiveLayers.length > 0}
|
||||
<SidebarUnit>
|
||||
<div class="flex justify-between">
|
||||
<h3>Active filters</h3>
|
||||
<h3><Tr t={t.activeFilters}/></h3>
|
||||
|
||||
<button class="as-link subtle self-end" on:click={() => clear()} style="margin-right: 0.75rem">
|
||||
Clear filters
|
||||
<Tr t={t.clearFilters}/>
|
||||
</button>
|
||||
</div>
|
||||
{#if loading}
|
||||
|
@ -82,9 +83,6 @@
|
|||
</div>
|
||||
{/each}
|
||||
</div>
|
||||
|
||||
|
||||
{/if}
|
||||
</SidebarUnit>
|
||||
|
||||
{/if}
|
||||
|
|
Loading…
Reference in a new issue