forked from MapComplete/MapComplete
More refactoring: using a decent, configurable datapipeline now
This commit is contained in:
parent
6ac8ec84e4
commit
e42a668c4a
17 changed files with 434 additions and 265 deletions
52
Logic/FeatureSource/FilteringFeatureSource.ts
Normal file
52
Logic/FeatureSource/FilteringFeatureSource.ts
Normal file
|
@ -0,0 +1,52 @@
|
|||
import FeatureSource from "./FeatureSource";
|
||||
import {UIEventSource} from "../UIEventSource";
|
||||
import LayerConfig from "../../Customizations/JSON/LayerConfig";
|
||||
import Loc from "../../Models/Loc";
|
||||
|
||||
export default class FilteringFeatureSource implements FeatureSource {
|
||||
public features: UIEventSource<{ feature: any; freshness: Date }[]> = new UIEventSource<{ feature: any; freshness: Date }[]>([]);
|
||||
|
||||
constructor(layers: {
|
||||
isDisplayed: UIEventSource<boolean>,
|
||||
layerDef: LayerConfig
|
||||
}[],
|
||||
location: UIEventSource<Loc>,
|
||||
upstream: FeatureSource) {
|
||||
|
||||
const layerDict = {};
|
||||
|
||||
const self = this;
|
||||
|
||||
function update() {
|
||||
console.log("UPdating...")
|
||||
const features: { feature: any, freshness: Date }[] = upstream.features.data;
|
||||
const newFeatures = features.filter(f => {
|
||||
const layerId = f.feature.properties._matching_layer_id;
|
||||
if (layerId === undefined) {
|
||||
console.error(f)
|
||||
throw "feature._matching_layer_id is undefined"
|
||||
}
|
||||
const layer: {
|
||||
isDisplayed: UIEventSource<boolean>,
|
||||
layerDef: LayerConfig
|
||||
} = layerDict[layerId];
|
||||
if (layer === undefined) {
|
||||
throw "No layer found with id " + layerId;
|
||||
}
|
||||
return layer.isDisplayed.data && (layer.layerDef.minzoom <= location.data.zoom);
|
||||
});
|
||||
self.features.setData(newFeatures);
|
||||
}
|
||||
for (const layer of layers) {
|
||||
layerDict[layer.layerDef.id] = layer;
|
||||
layer.isDisplayed.addCallback(update)
|
||||
}
|
||||
upstream.features.addCallback(update);
|
||||
location.map(l => l.zoom).addCallback(update);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue