forked from MapComplete/MapComplete
Feature: first version of clustering at low zoom levels, filters don't update yet (WIP)
This commit is contained in:
parent
4e033a93a5
commit
8360ab9a8b
11 changed files with 562 additions and 262 deletions
38
src/Logic/FeatureSource/Sources/IfVisibleFeatureSource.ts
Normal file
38
src/Logic/FeatureSource/Sources/IfVisibleFeatureSource.ts
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
import { FeatureSource } from "../FeatureSource"
|
||||
import { Feature } from "geojson"
|
||||
import { Store, UIEventSource } from "../../UIEventSource"
|
||||
|
||||
export class IfVisibleFeatureSource<T extends Feature> implements FeatureSource<T> {
|
||||
|
||||
private readonly _features: UIEventSource<T[]> = new UIEventSource<T[]>([])
|
||||
public readonly features: Store<T[]> = this._features
|
||||
|
||||
constructor(upstream: FeatureSource<T>, visible: Store<boolean>) {
|
||||
|
||||
let dirty = false
|
||||
upstream.features.addCallbackAndRun(features => {
|
||||
if (!visible.data) {
|
||||
console.log(">>> not writing data as not visible")
|
||||
dirty = true
|
||||
return
|
||||
}
|
||||
this._features.set(features)
|
||||
dirty = false
|
||||
})
|
||||
|
||||
visible.addCallbackAndRun(isVisible => {
|
||||
if (isVisible && dirty) {
|
||||
this._features.set(upstream.features.data)
|
||||
dirty = false
|
||||
}
|
||||
if (!visible) {
|
||||
this._features.set([])
|
||||
}
|
||||
|
||||
})
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue