forked from MapComplete/MapComplete
Tying the knot: calculatedTags will update every time new data are added to the map. Fixes part of #287
This commit is contained in:
parent
4dda8fdcfa
commit
bc605371f5
3 changed files with 41 additions and 25 deletions
|
@ -16,7 +16,7 @@ import RegisteringFeatureSource from "./RegisteringFeatureSource";
|
||||||
|
|
||||||
export default class FeaturePipeline implements FeatureSource {
|
export default class FeaturePipeline implements FeatureSource {
|
||||||
|
|
||||||
public features: UIEventSource<{ feature: any; freshness: Date }[]>;
|
public features: UIEventSource<{ feature: any; freshness: Date }[]> = new UIEventSource<{feature: any; freshness: Date}[]>([]);
|
||||||
|
|
||||||
public readonly name = "FeaturePipeline"
|
public readonly name = "FeaturePipeline"
|
||||||
|
|
||||||
|
@ -83,7 +83,8 @@ export default class FeaturePipeline implements FeatureSource {
|
||||||
selectedElement,
|
selectedElement,
|
||||||
merged
|
merged
|
||||||
));
|
));
|
||||||
this.features = source.features;
|
|
||||||
|
source.features.syncWith(this.features)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -4,6 +4,7 @@ import State from "../../State";
|
||||||
import Hash from "../Web/Hash";
|
import Hash from "../Web/Hash";
|
||||||
import MetaTagging from "../MetaTagging";
|
import MetaTagging from "../MetaTagging";
|
||||||
import ExtractRelations from "../Osm/ExtractRelations";
|
import ExtractRelations from "../Osm/ExtractRelations";
|
||||||
|
import FeatureSourceMerger from "./FeatureSourceMerger";
|
||||||
|
|
||||||
export default class MetaTaggingFeatureSource implements FeatureSource {
|
export default class MetaTaggingFeatureSource implements FeatureSource {
|
||||||
public readonly features: UIEventSource<{ feature: any; freshness: Date }[]> = new UIEventSource<{ feature: any; freshness: Date }[]>(undefined);
|
public readonly features: UIEventSource<{ feature: any; freshness: Date }[]> = new UIEventSource<{ feature: any; freshness: Date }[]>(undefined);
|
||||||
|
@ -14,6 +15,10 @@ export default class MetaTaggingFeatureSource implements FeatureSource {
|
||||||
const self = this;
|
const self = this;
|
||||||
this.name = "MetaTagging of " + source.name
|
this.name = "MetaTagging of " + source.name
|
||||||
|
|
||||||
|
if(allFeaturesSource.features === undefined){
|
||||||
|
throw ("Initialize the featuresource fully first!"+allFeaturesSource.name)
|
||||||
|
}
|
||||||
|
|
||||||
function update() {
|
function update() {
|
||||||
const featuresFreshness = source.features.data
|
const featuresFreshness = source.features.data
|
||||||
if (featuresFreshness === undefined) {
|
if (featuresFreshness === undefined) {
|
||||||
|
|
|
@ -3,7 +3,6 @@ import SimpleMetaTagger from "./SimpleMetaTagger";
|
||||||
import {ExtraFunction} from "./ExtraFunction";
|
import {ExtraFunction} from "./ExtraFunction";
|
||||||
import {Relation} from "./Osm/ExtractRelations";
|
import {Relation} from "./Osm/ExtractRelations";
|
||||||
import FeatureSource from "./FeatureSource/FeatureSource";
|
import FeatureSource from "./FeatureSource/FeatureSource";
|
||||||
import State from "../State";
|
|
||||||
|
|
||||||
|
|
||||||
interface Params {
|
interface Params {
|
||||||
|
@ -48,8 +47,12 @@ export default class MetaTagging {
|
||||||
layerFuncs.set(layer.id, this.createRetaggingFunc(layer));
|
layerFuncs.set(layer.id, this.createRetaggingFunc(layer));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
allKnownFeatures.features.addCallbackAndRun(newFeatures => {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
const featuresPerLayer = new Map<string, any[]>();
|
const featuresPerLayer = new Map<string, any[]>();
|
||||||
for (const feature of (allKnownFeatures.features?.data ?? features ?? [])) {
|
for (const feature of (newFeatures.concat(features))) {
|
||||||
|
|
||||||
const key = feature.feature._matching_layer_id;
|
const key = feature.feature._matching_layer_id;
|
||||||
if (!featuresPerLayer.has(key)) {
|
if (!featuresPerLayer.has(key)) {
|
||||||
|
@ -75,6 +78,13 @@ export default class MetaTagging {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -105,7 +115,7 @@ export default class MetaTagging {
|
||||||
}
|
}
|
||||||
if (typeof result !== "string") {
|
if (typeof result !== "string") {
|
||||||
// Make sure it is a string!
|
// Make sure it is a string!
|
||||||
result = "" + result;
|
result = JSON.stringify(result);
|
||||||
}
|
}
|
||||||
feature.properties[key] = result;
|
feature.properties[key] = result;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue