Use addCallbackAndRunD
This commit is contained in:
parent
8d9a992507
commit
ba04beab2c
4 changed files with 5 additions and 12 deletions
|
@ -16,11 +16,7 @@ export default class LocalStorageSaver implements FeatureSource {
|
||||||
constructor(source: FeatureSource, layout: UIEventSource<LayoutConfig>) {
|
constructor(source: FeatureSource, layout: UIEventSource<LayoutConfig>) {
|
||||||
this.features = source.features;
|
this.features = source.features;
|
||||||
|
|
||||||
this.features.addCallbackAndRun(features => {
|
this.features.addCallbackAndRunD(features => {
|
||||||
if (features === undefined) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const now = new Date().getTime()
|
const now = new Date().getTime()
|
||||||
features = features.filter(f => layout.data.cacheTimeout > Math.abs(now - f.freshness.getTime())/1000)
|
features = features.filter(f => layout.data.cacheTimeout > Math.abs(now - f.freshness.getTime())/1000)
|
||||||
|
|
||||||
|
|
|
@ -11,8 +11,6 @@ export default class LocalStorageSource implements FeatureSource {
|
||||||
this.features = new UIEventSource<{ feature: any; freshness: Date }[]>([])
|
this.features = new UIEventSource<{ feature: any; freshness: Date }[]>([])
|
||||||
const key = LocalStorageSaver.storageKey + layout.data.id
|
const key = LocalStorageSaver.storageKey + layout.data.id
|
||||||
layout.addCallbackAndRun(_ => {
|
layout.addCallbackAndRun(_ => {
|
||||||
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const fromStorage = localStorage.getItem(key);
|
const fromStorage = localStorage.getItem(key);
|
||||||
if (fromStorage == null) {
|
if (fromStorage == null) {
|
||||||
|
|
|
@ -3,7 +3,6 @@ import {UIEventSource} from "../UIEventSource";
|
||||||
import {OsmObject} from "../Osm/OsmObject";
|
import {OsmObject} from "../Osm/OsmObject";
|
||||||
import State from "../../State";
|
import State from "../../State";
|
||||||
import {Utils} from "../../Utils";
|
import {Utils} from "../../Utils";
|
||||||
import Loc from "../../Models/Loc";
|
|
||||||
|
|
||||||
|
|
||||||
export default class OsmApiFeatureSource implements FeatureSource {
|
export default class OsmApiFeatureSource implements FeatureSource {
|
||||||
|
@ -21,10 +20,10 @@ export default class OsmApiFeatureSource implements FeatureSource {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
console.debug("Downloading", id, "from the OSM-API")
|
console.debug("Downloading", id, "from the OSM-API")
|
||||||
OsmObject.DownloadObject(id, (element, meta) => {
|
OsmObject.DownloadObject(id).addCallbackAndRunD(element => {
|
||||||
const geojson = element.asGeoJson();
|
const geojson = element.asGeoJson();
|
||||||
geojson.id = geojson.properties.id;
|
geojson.id = geojson.properties.id;
|
||||||
this.features.setData([{feature: geojson, freshness: meta["_last_edit:timestamp"]}])
|
this.features.setData([{feature: geojson, freshness: element.timestamp}])
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -9,8 +9,8 @@ export default class RegisteringFeatureSource implements FeatureSource {
|
||||||
constructor(source: FeatureSource) {
|
constructor(source: FeatureSource) {
|
||||||
this.features = source.features;
|
this.features = source.features;
|
||||||
this.name = "RegisteringSource of " + source.name;
|
this.name = "RegisteringSource of " + source.name;
|
||||||
this.features.addCallbackAndRun(features => {
|
this.features.addCallbackAndRunD(features => {
|
||||||
for (const feature of features ?? []) {
|
for (const feature of features) {
|
||||||
State.state.allElements.addOrGetElement(feature.feature)
|
State.state.allElements.addOrGetElement(feature.feature)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in a new issue