Huge refactoring of the feature pipeline, WIP

This commit is contained in:
Pieter Vander Vennet 2021-09-20 17:14:55 +02:00
parent 7793297348
commit 973b5d8bbe
25 changed files with 522 additions and 591 deletions

View file

@ -0,0 +1,35 @@
import {FeatureSourceForLayer} from "./FeatureSource";
import {Utils} from "../../Utils";
/***
* Saves all the features that are passed in to localstorage, so they can be retrieved on the next run
*
* Technically, more an Actor then a featuresource, but it fits more neatly this ay
*/
export default class LocalStorageSaverActor {
public static readonly storageKey: string = "cached-features";
constructor(source: FeatureSourceForLayer, x: number, y: number, z: number) {
source.features.addCallbackAndRunD(features => {
const index = Utils.tile_index(z, x, y)
const key = `${LocalStorageSaverActor.storageKey}-${source.layer.layerDef.id}-${index}`
const now = new Date().getTime()
if (features.length == 0) {
return;
}
try {
localStorage.setItem(key, JSON.stringify(features));
console.log("Saved ", features.length, "elements to", key)
localStorage.setItem(key + "-time", JSON.stringify(now))
} catch (e) {
console.warn("Could not save the features to local storage:", e)
}
})
}
}

View file

@ -0,0 +1,19 @@
import FeatureSource from "./FeatureSource";
import {UIEventSource} from "../UIEventSource";
import State from "../../State";
export default class RegisteringAllFromFeatureSourceActor {
public readonly features: UIEventSource<{ feature: any; freshness: Date }[]>;
public readonly name;
constructor(source: FeatureSource) {
this.features = source.features;
this.name = "RegisteringSource of " + source.name;
this.features.addCallbackAndRunD(features => {
for (const feature of features) {
State.state.allElements.addOrGetElement(feature.feature)
}
})
}
}