Feature: first version of clustering at low zoom levels, filters don't update yet (WIP)

This commit is contained in:
Pieter Vander Vennet 2025-07-21 12:57:04 +02:00
parent 4e033a93a5
commit 8360ab9a8b
11 changed files with 562 additions and 262 deletions

View 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([])
}
})
}
}