Fix metatagging and calculated tags in heterogenous data settings

This commit is contained in:
Pieter Vander Vennet 2021-05-16 15:34:44 +02:00
parent 93296d5378
commit d547b9f968
14 changed files with 374 additions and 246 deletions

View file

@ -0,0 +1,12 @@
import FeatureSource from "./FeatureSource";
import {UIEventSource} from "../UIEventSource";
export default class DummyFeatureSource implements FeatureSource{
public readonly features: UIEventSource<{ feature: any; freshness: Date }[]>;
public readonly name: string = "Dummy (static) feature source";
constructor(features: UIEventSource<{ feature: any; freshness: Date }[]>) {
this.features = features;
}
}

View file

@ -35,7 +35,7 @@ export default class FeaturePipeline implements FeatureSource {
const amendedOverpassSource =
new RememberingSource(
new LocalStorageSaver(
new MetaTaggingFeatureSource(
new MetaTaggingFeatureSource(this,
new FeatureDuplicatorPerLayer(flayers,
new RegisteringFeatureSource(
updater)
@ -43,18 +43,24 @@ export default class FeaturePipeline implements FeatureSource {
const geojsonSources: FeatureSource [] = GeoJsonSource
.ConstructMultiSource(flayers.data, locationControl)
.map(geojsonSource => new RegisteringFeatureSource(new FeatureDuplicatorPerLayer(flayers, geojsonSource)));
.map(geojsonSource => {
let source = new RegisteringFeatureSource(new FeatureDuplicatorPerLayer(flayers, geojsonSource));
if(!geojsonSource.isOsmCache){
source = new MetaTaggingFeatureSource(this, source, updater.features);
}
return source
});
const amendedLocalStorageSource =
new RememberingSource(new RegisteringFeatureSource(new FeatureDuplicatorPerLayer(flayers, new LocalStorageSource(layout))
));
newPoints = new MetaTaggingFeatureSource(
newPoints = new MetaTaggingFeatureSource(this,
new FeatureDuplicatorPerLayer(flayers,
new RegisteringFeatureSource(newPoints)));
const amendedOsmApiSource = new RememberingSource(
new MetaTaggingFeatureSource(
new MetaTaggingFeatureSource(this,
new FeatureDuplicatorPerLayer(flayers,
new RegisteringFeatureSource(fromOsmApi))));

View file

@ -19,6 +19,7 @@ export default class GeoJsonSource implements FeatureSource {
private onFail: ((errorMsg: any, url: string) => void) = undefined;
private readonly layerId: string;
private readonly seenids: Set<string> = new Set<string>()
public readonly isOsmCache: boolean
private constructor(locationControl: UIEventSource<Loc>,
flayer: { isDisplayed: UIEventSource<boolean>, layerDef: LayerConfig },
@ -27,6 +28,8 @@ export default class GeoJsonSource implements FeatureSource {
let url = flayer.layerDef.source.geojsonSource.replace("{layer}", flayer.layerDef.id);
this.name = "GeoJsonSource of " + url;
const zoomLevel = flayer.layerDef.source.geojsonZoomLevel;
this.isOsmCache = flayer.layerDef.source.isOsmCacheLayer;
this.features = new UIEventSource<{ feature: any; freshness: Date }[]>([])

View file

@ -6,28 +6,38 @@ import MetaTagging from "../MetaTagging";
import ExtractRelations from "../Osm/ExtractRelations";
export default class MetaTaggingFeatureSource implements FeatureSource {
public readonly features: UIEventSource<{ feature: any; freshness: Date }[]> = new UIEventSource<{feature: any; freshness: Date}[]>(undefined);
public readonly name;
constructor(source: FeatureSource) {
const self = this;
this.name = "MetaTagging of "+source.name
source.features.addCallbackAndRun((featuresFreshness: { feature: any, freshness: Date }[]) => {
if (featuresFreshness === undefined) {
return;
}
featuresFreshness.forEach(featureFresh => {
const feature = featureFresh.feature;
if (Hash.hash.data === feature.properties.id) {
State.state.selectedElement.setData(feature);
}
})
public readonly features: UIEventSource<{ feature: any; freshness: Date }[]> = new UIEventSource<{ feature: any; freshness: Date }[]>(undefined);
MetaTagging.addMetatags(featuresFreshness, State.state.knownRelations.data, State.state.layoutToUse.data.layers);
self.features.setData(featuresFreshness);
});
public readonly name;
constructor(allFeaturesSource: FeatureSource, source: FeatureSource, updateTrigger?: UIEventSource<any>) {
const self = this;
this.name = "MetaTagging of " + source.name
function update() {
const featuresFreshness = source.features.data
if (featuresFreshness === undefined) {
return;
}
featuresFreshness.forEach(featureFresh => {
const feature = featureFresh.feature;
if (Hash.hash.data === feature.properties.id) {
State.state.selectedElement.setData(feature);
}
})
MetaTagging.addMetatags(featuresFreshness,
allFeaturesSource,
State.state.knownRelations.data, State.state.layoutToUse.data.layers);
self.features.setData(featuresFreshness);
}
source.features.addCallbackAndRun(_ => update());
updateTrigger?.addCallback(_ => {
console.debug("Updating because of external call")
update();
})
}
}