Fix: don't show all items if favourites is shown

This commit is contained in:
Pieter Vander Vennet 2024-11-25 02:06:28 +01:00
parent ad4afbaf52
commit 3292307208
4 changed files with 42 additions and 20 deletions

View file

@ -13,60 +13,74 @@ export default class FilteringFeatureSource implements FeatureSource {
private readonly _is_dirty = new UIEventSource(false)
private readonly _layer: FilteredLayer
private previousFeatureSet: Set<any> = undefined
private readonly _zoomlevel: Store<number>
private readonly _selectedElement: Store<Feature>
constructor(
layer: FilteredLayer,
upstream: FeatureSource,
fetchStore?: (id: string) => Store<Record<string, string>>,
globalFilters?: Store<GlobalFilter[]>,
metataggingUpdated?: Store<any>
metataggingUpdated?: Store<any>,
zoomlevel?: Store<number>,
selectedElement?: Store<Feature>
) {
this.upstream = upstream
this._fetchStore = fetchStore
this._layer = layer
this._globalFilters = globalFilters
this._zoomlevel = zoomlevel
this._selectedElement = selectedElement
const self = this
upstream.features.addCallback(() => {
self.update()
this.update()
})
layer.isDisplayed.addCallback(() => {
self.update()
this.update()
})
layer.appliedFilters.forEach((value) =>
value.addCallback((_) => {
self.update()
this.update()
})
)
this._is_dirty.stabilized(1000).addCallbackAndRunD((dirty) => {
if (dirty) {
self.update()
this.update()
}
})
metataggingUpdated?.addCallback((_) => {
self._is_dirty.setData(true)
metataggingUpdated?.addCallback(() => {
this._is_dirty.setData(true)
})
globalFilters?.addCallback((_) => {
self.update()
globalFilters?.addCallback(() => {
this.update()
})
selectedElement?.addCallback(() => this.update())
zoomlevel?.mapD(z => Math.floor(z)).addCallback(() => this.update())
this.update()
}
private update() {
const self = this
const layer = this._layer
const features: Feature[] = this.upstream.features.data ?? []
const includedFeatureIds = new Set<string>()
const globalFilters = self._globalFilters?.data?.map((f) => f)
const globalFilters = this._globalFilters?.data?.map((f) => f)
const zoomlevel = this._zoomlevel?.data
const selectedElement = this._selectedElement?.data?.properties?.id
const newFeatures = (features ?? []).filter((f) => {
self.registerCallback(f.properties.id)
this.registerCallback(f.properties.id)
if (!layer.isShown(f.properties, globalFilters)) {
if(selectedElement === f.properties.id){
return true
}
if (!layer.isShown(f.properties, globalFilters, zoomlevel)) {
return false
}

View file

@ -210,7 +210,7 @@ export default class FilteredLayer {
* - the specified 'global filters'
* - the 'isShown'-filter set by the layer
*/
public isShown(properties: Record<string, string>, globalFilters?: GlobalFilter[]): boolean {
public isShown(properties: Record<string, string>, globalFilters?: GlobalFilter[], zoomlevel?: number): boolean {
if (properties._deleted === "yes") {
return false
}
@ -219,9 +219,10 @@ export default class FilteredLayer {
if (neededTags !== undefined) {
const doesMatch = neededTags.matchesProperties(properties)
if (globalFilter.forceShowOnMatch) {
return doesMatch || this.isDisplayed.data
}
if (!doesMatch) {
if(doesMatch){
return true
}
} else if (!doesMatch) {
return false
}
}
@ -240,6 +241,10 @@ export default class FilteredLayer {
}
}
if(zoomlevel !== undefined && (this.layerDef.minzoom > zoomlevel || this.layerDef.minzoomVisible < zoomlevel)){
return false
}
return true
}

View file

@ -159,7 +159,7 @@ export default class LayerConfig extends WithContextLoader {
if (json["minZoom"] !== undefined) {
throw "At " + context + ": minzoom is written all lowercase"
}
this.minzoomVisible = json.minzoomVisible ?? this.minzoom
this.minzoomVisible = json.minzoomVisible ?? 100
this.shownByDefault = json.shownByDefault ?? true
this.doCount = json.isCounted ?? this.shownByDefault ?? true
this.forceLoad = json.forceLoad ?? false

View file

@ -473,7 +473,10 @@ export default class ThemeViewState implements SpecialVisualizationState {
fs.layer,
fs,
(id) => this.featureProperties.getStore(id),
this.layerState.globalFilters
this.layerState.globalFilters,
undefined,
this.mapProperties.zoom,
this.selectedElement
)
filteringFeatureSource.set(layerName, filtered)