Fix: show favourites in loaded layers if favourites are enabled

This commit is contained in:
Pieter Vander Vennet 2024-11-05 19:08:10 +01:00
parent ca3a1acf53
commit e65f61d296
3 changed files with 50 additions and 14 deletions

View file

@ -36,7 +36,7 @@ export default class FilteredLayer {
constructor( constructor(
layer: LayerConfig, layer: LayerConfig,
appliedFilters?: ReadonlyMap<string, UIEventSource<undefined | number | string>>, appliedFilters?: ReadonlyMap<string, UIEventSource<undefined | number | string>>,
isDisplayed?: UIEventSource<boolean> isDisplayed?: UIEventSource<boolean>,
) { ) {
this.layerDef = layer this.layerDef = layer
this.isDisplayed = isDisplayed ?? new UIEventSource(true) this.isDisplayed = isDisplayed ?? new UIEventSource(true)
@ -82,25 +82,25 @@ export default class FilteredLayer {
layer: LayerConfig, layer: LayerConfig,
context: string, context: string,
osmConnection: OsmConnection, osmConnection: OsmConnection,
enabledByDefault?: Store<boolean> enabledByDefault?: Store<boolean>,
) { ) {
let isDisplayed: UIEventSource<boolean> let isDisplayed: UIEventSource<boolean>
if (layer.syncSelection === "local") { if (layer.syncSelection === "local") {
isDisplayed = LocalStorageSource.getParsed( isDisplayed = LocalStorageSource.getParsed(
context + "-layer-" + layer.id + "-enabled", context + "-layer-" + layer.id + "-enabled",
layer.shownByDefault layer.shownByDefault,
) )
} else if (layer.syncSelection === "theme-only") { } else if (layer.syncSelection === "theme-only") {
isDisplayed = FilteredLayer.getPref( isDisplayed = FilteredLayer.getPref(
osmConnection, osmConnection,
context + "-layer-" + layer.id + "-enabled", context + "-layer-" + layer.id + "-enabled",
layer layer,
) )
} else if (layer.syncSelection === "global") { } else if (layer.syncSelection === "global") {
isDisplayed = FilteredLayer.getPref( isDisplayed = FilteredLayer.getPref(
osmConnection, osmConnection,
"layer-" + layer.id + "-enabled", "layer-" + layer.id + "-enabled",
layer layer,
) )
} else { } else {
let isShown = layer.shownByDefault let isShown = layer.shownByDefault
@ -110,7 +110,7 @@ export default class FilteredLayer {
isDisplayed = QueryParameters.GetBooleanQueryParameter( isDisplayed = QueryParameters.GetBooleanQueryParameter(
FilteredLayer.queryParameterKey(layer), FilteredLayer.queryParameterKey(layer),
isShown, isShown,
"Whether or not layer " + layer.id + " is shown" "Whether or not layer " + layer.id + " is shown",
) )
} }
@ -145,7 +145,7 @@ export default class FilteredLayer {
*/ */
private static fieldsToTags( private static fieldsToTags(
option: FilterConfigOption, option: FilterConfigOption,
fieldstate: string | Record<string, string> fieldstate: string | Record<string, string>,
): TagsFilter | undefined { ): TagsFilter | undefined {
let properties: Record<string, string> let properties: Record<string, string>
if (typeof fieldstate === "string") { if (typeof fieldstate === "string") {
@ -181,7 +181,7 @@ export default class FilteredLayer {
private static getPref( private static getPref(
osmConnection: OsmConnection, osmConnection: OsmConnection,
key: string, key: string,
layer: LayerConfig layer: LayerConfig,
): UIEventSource<boolean> { ): UIEventSource<boolean> {
return osmConnection.GetPreference(key, layer.shownByDefault + "").sync( return osmConnection.GetPreference(key, layer.shownByDefault + "").sync(
(v) => { (v) => {
@ -196,7 +196,7 @@ export default class FilteredLayer {
return undefined return undefined
} }
return "" + b return "" + b
} },
) )
} }
@ -216,8 +216,14 @@ export default class FilteredLayer {
} }
for (const globalFilter of globalFilters ?? []) { for (const globalFilter of globalFilters ?? []) {
const neededTags = globalFilter.osmTags const neededTags = globalFilter.osmTags
if (neededTags !== undefined && !neededTags.matchesProperties(properties)) { if (neededTags !== undefined) {
return false const doesMatch = neededTags.matchesProperties(properties)
if (globalFilter.forceShowOnMatch) {
return doesMatch || this.isDisplayed.data
}
if (!doesMatch) {
return false
}
} }
} }
{ {

View file

@ -4,6 +4,10 @@ import { TagsFilter } from "../Logic/Tags/TagsFilter"
export interface GlobalFilter { export interface GlobalFilter {
osmTags: TagsFilter osmTags: TagsFilter
/**
* If set, this object will be shown instead of hidden, even if the layer is not displayed
*/
forceShowOnMatch?: boolean,
state: number | string | undefined state: number | string | undefined
id: string id: string
onNewPoint: { onNewPoint: {

View file

@ -76,6 +76,7 @@ import { GeocodeResult, GeocodingUtils } from "../Logic/Search/GeocodingProvider
import SearchState from "../Logic/State/SearchState" import SearchState from "../Logic/State/SearchState"
import { ShowDataLayerOptions } from "../UI/Map/ShowDataLayerOptions" import { ShowDataLayerOptions } from "../UI/Map/ShowDataLayerOptions"
import { PanoramaxUploader } from "../Logic/ImageProviders/Panoramax" import { PanoramaxUploader } from "../Logic/ImageProviders/Panoramax"
import { Tag } from "../Logic/Tags/Tag"
/** /**
* *
@ -443,9 +444,16 @@ export default class ThemeViewState implements SpecialVisualizationState {
const filteringFeatureSource = new Map<string, FilteringFeatureSource>() const filteringFeatureSource = new Map<string, FilteringFeatureSource>()
this.perLayer.forEach((fs, layerName) => { this.perLayer.forEach((fs, layerName) => {
const doShowLayer = this.mapProperties.zoom.map( const doShowLayer = this.mapProperties.zoom.map(
(z) => (z) => {
(fs.layer.isDisplayed?.data ?? true) && z >= (fs.layer.layerDef?.minzoom ?? 0), if ((fs.layer.isDisplayed?.data ?? true) && z >= (fs.layer.layerDef?.minzoom ?? 0)){
[fs.layer.isDisplayed] return true
}
if(this.layerState.globalFilters.data.some(f => f.forceShowOnMatch)){
return true
}
return false
},
[fs.layer.isDisplayed, this.layerState.globalFilters]
) )
if (!doShowLayer.data && this.featureSwitches.featureSwitchFilter.data === false) { if (!doShowLayer.data && this.featureSwitches.featureSwitchFilter.data === false) {
@ -984,6 +992,24 @@ export default class ThemeViewState implements SpecialVisualizationState {
this.userRelatedState.showScale.addCallbackAndRun((showScale) => { this.userRelatedState.showScale.addCallbackAndRun((showScale) => {
this.mapProperties.showScale.set(showScale) this.mapProperties.showScale.set(showScale)
}) })
this.layerState.filteredLayers.get("favourite").isDisplayed.addCallbackAndRunD(favouritesShown => {
const oldGlobal = this.layerState.globalFilters.data
const key = "show-favourite"
if(favouritesShown){
this.layerState.globalFilters.set([...oldGlobal, {
forceShowOnMatch: true,
id:key,
osmTags: new Tag("_favourite","yes"),
state: 0,
onNewPoint: undefined
}])
}else{
this.layerState.globalFilters.set(oldGlobal.filter(gl => gl.id !== key))
}
})
new ThemeViewStateHashActor(this) new ThemeViewStateHashActor(this)
new MetaTagging(this) new MetaTagging(this)
new TitleHandler(this.selectedElement, this) new TitleHandler(this.selectedElement, this)