forked from MapComplete/MapComplete
Fix: don't show all items if favourites is shown
This commit is contained in:
parent
ad4afbaf52
commit
3292307208
4 changed files with 42 additions and 20 deletions
|
@ -13,60 +13,74 @@ export default class FilteringFeatureSource implements FeatureSource {
|
||||||
private readonly _is_dirty = new UIEventSource(false)
|
private readonly _is_dirty = new UIEventSource(false)
|
||||||
private readonly _layer: FilteredLayer
|
private readonly _layer: FilteredLayer
|
||||||
private previousFeatureSet: Set<any> = undefined
|
private previousFeatureSet: Set<any> = undefined
|
||||||
|
private readonly _zoomlevel: Store<number>
|
||||||
|
private readonly _selectedElement: Store<Feature>
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
layer: FilteredLayer,
|
layer: FilteredLayer,
|
||||||
upstream: FeatureSource,
|
upstream: FeatureSource,
|
||||||
fetchStore?: (id: string) => Store<Record<string, string>>,
|
fetchStore?: (id: string) => Store<Record<string, string>>,
|
||||||
globalFilters?: Store<GlobalFilter[]>,
|
globalFilters?: Store<GlobalFilter[]>,
|
||||||
metataggingUpdated?: Store<any>
|
metataggingUpdated?: Store<any>,
|
||||||
|
zoomlevel?: Store<number>,
|
||||||
|
selectedElement?: Store<Feature>
|
||||||
) {
|
) {
|
||||||
this.upstream = upstream
|
this.upstream = upstream
|
||||||
this._fetchStore = fetchStore
|
this._fetchStore = fetchStore
|
||||||
this._layer = layer
|
this._layer = layer
|
||||||
this._globalFilters = globalFilters
|
this._globalFilters = globalFilters
|
||||||
|
this._zoomlevel = zoomlevel
|
||||||
|
this._selectedElement = selectedElement
|
||||||
|
|
||||||
const self = this
|
|
||||||
upstream.features.addCallback(() => {
|
upstream.features.addCallback(() => {
|
||||||
self.update()
|
this.update()
|
||||||
})
|
})
|
||||||
layer.isDisplayed.addCallback(() => {
|
layer.isDisplayed.addCallback(() => {
|
||||||
self.update()
|
this.update()
|
||||||
})
|
})
|
||||||
|
|
||||||
layer.appliedFilters.forEach((value) =>
|
layer.appliedFilters.forEach((value) =>
|
||||||
value.addCallback((_) => {
|
value.addCallback((_) => {
|
||||||
self.update()
|
this.update()
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
|
|
||||||
this._is_dirty.stabilized(1000).addCallbackAndRunD((dirty) => {
|
this._is_dirty.stabilized(1000).addCallbackAndRunD((dirty) => {
|
||||||
if (dirty) {
|
if (dirty) {
|
||||||
self.update()
|
this.update()
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
metataggingUpdated?.addCallback((_) => {
|
metataggingUpdated?.addCallback(() => {
|
||||||
self._is_dirty.setData(true)
|
this._is_dirty.setData(true)
|
||||||
})
|
})
|
||||||
|
|
||||||
globalFilters?.addCallback((_) => {
|
globalFilters?.addCallback(() => {
|
||||||
self.update()
|
this.update()
|
||||||
})
|
})
|
||||||
|
|
||||||
|
selectedElement?.addCallback(() => this.update())
|
||||||
|
|
||||||
|
zoomlevel?.mapD(z => Math.floor(z)).addCallback(() => this.update())
|
||||||
|
|
||||||
this.update()
|
this.update()
|
||||||
}
|
}
|
||||||
|
|
||||||
private update() {
|
private update() {
|
||||||
const self = this
|
|
||||||
const layer = this._layer
|
const layer = this._layer
|
||||||
const features: Feature[] = this.upstream.features.data ?? []
|
const features: Feature[] = this.upstream.features.data ?? []
|
||||||
const includedFeatureIds = new Set<string>()
|
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) => {
|
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
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -210,7 +210,7 @@ export default class FilteredLayer {
|
||||||
* - the specified 'global filters'
|
* - the specified 'global filters'
|
||||||
* - the 'isShown'-filter set by the layer
|
* - 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") {
|
if (properties._deleted === "yes") {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
@ -219,9 +219,10 @@ export default class FilteredLayer {
|
||||||
if (neededTags !== undefined) {
|
if (neededTags !== undefined) {
|
||||||
const doesMatch = neededTags.matchesProperties(properties)
|
const doesMatch = neededTags.matchesProperties(properties)
|
||||||
if (globalFilter.forceShowOnMatch) {
|
if (globalFilter.forceShowOnMatch) {
|
||||||
return doesMatch || this.isDisplayed.data
|
if(doesMatch){
|
||||||
}
|
return true
|
||||||
if (!doesMatch) {
|
}
|
||||||
|
} else if (!doesMatch) {
|
||||||
return false
|
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
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -159,7 +159,7 @@ export default class LayerConfig extends WithContextLoader {
|
||||||
if (json["minZoom"] !== undefined) {
|
if (json["minZoom"] !== undefined) {
|
||||||
throw "At " + context + ": minzoom is written all lowercase"
|
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.shownByDefault = json.shownByDefault ?? true
|
||||||
this.doCount = json.isCounted ?? this.shownByDefault ?? true
|
this.doCount = json.isCounted ?? this.shownByDefault ?? true
|
||||||
this.forceLoad = json.forceLoad ?? false
|
this.forceLoad = json.forceLoad ?? false
|
||||||
|
|
|
@ -473,7 +473,10 @@ export default class ThemeViewState implements SpecialVisualizationState {
|
||||||
fs.layer,
|
fs.layer,
|
||||||
fs,
|
fs,
|
||||||
(id) => this.featureProperties.getStore(id),
|
(id) => this.featureProperties.getStore(id),
|
||||||
this.layerState.globalFilters
|
this.layerState.globalFilters,
|
||||||
|
undefined,
|
||||||
|
this.mapProperties.zoom,
|
||||||
|
this.selectedElement
|
||||||
)
|
)
|
||||||
filteringFeatureSource.set(layerName, filtered)
|
filteringFeatureSource.set(layerName, filtered)
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue