Fix hiding and showing of features

This commit is contained in:
Pieter Vander Vennet 2021-02-14 19:45:02 +01:00
parent d4f107c81a
commit bc1863dcb6
12 changed files with 160 additions and 137 deletions

View file

@ -44,10 +44,12 @@ export default class SelectedFeatureHandler {
// Feature already selected
return;
}
console.log("Selecting a feature from the hash...")
for (const feature of features) {
const id = feature.feature?.properties?.id;
if(id === this._hash.data){
this._selectedFeature.setData(feature.feature);
break;
}
}
}

View file

@ -52,9 +52,6 @@ export default class FeatureDuplicatorPerLayer implements FeatureSource {
}
}
}
if(!foundALayer){
console.error("LAYER DEDUP PANIC: no suitable layer found for ", f, JSON.stringify(f), "within layers", layers)
}
}
return newFeatures;

View file

@ -1,5 +1,4 @@
import FilteringFeatureSource from "../FeatureSource/FilteringFeatureSource";
import State from "../../State";
import FeatureSourceMerger from "../FeatureSource/FeatureSourceMerger";
import RememberingSource from "../FeatureSource/RememberingSource";
import WayHandlingApplyingFeatureSource from "../FeatureSource/WayHandlingApplyingFeatureSource";
@ -11,6 +10,7 @@ import LocalStorageSaver from "./LocalStorageSaver";
import LayerConfig from "../../Customizations/JSON/LayerConfig";
import LocalStorageSource from "./LocalStorageSource";
import LayoutConfig from "../../Customizations/JSON/LayoutConfig";
import Loc from "../../Models/Loc";
export default class FeaturePipeline implements FeatureSource {
@ -18,7 +18,9 @@ export default class FeaturePipeline implements FeatureSource {
constructor(flayers: { isDisplayed: UIEventSource<boolean>, layerDef: LayerConfig }[],
updater: FeatureSource,
layout: UIEventSource<LayoutConfig>) {
layout: UIEventSource<LayoutConfig>,
newPoints: FeatureSource,
locationControl: UIEventSource<Loc>) {
const amendedOverpassSource =
new RememberingSource(
@ -34,15 +36,18 @@ export default class FeaturePipeline implements FeatureSource {
new NoOverlapSource(flayers, new FeatureDuplicatorPerLayer(flayers, new LocalStorageSource(layout)))
));
newPoints = new FeatureDuplicatorPerLayer(flayers, newPoints);
const merged = new FeatureSourceMerger([
amendedOverpassSource,
new FeatureDuplicatorPerLayer(flayers, State.state.changes),
amendedLocalStorageSource
amendedLocalStorageSource,
newPoints
]);
const source =
new FilteringFeatureSource(
flayers,
State.state.locationControl,
locationControl,
merged
);
this.features = source.features;

View file

@ -13,29 +13,35 @@ export default class FilteringFeatureSource implements FeatureSource {
location: UIEventSource<Loc>,
upstream: FeatureSource) {
const layerDict = {};
const self = this;
const layerDict = {};
for (const layer of layers) {
layerDict[layer.layerDef.id] = layer;
}
function update() {
console.log("Updating the filtering layer")
const features: { feature: any, freshness: Date }[] = upstream.features.data;
const newFeatures = features.filter(f => {
const layerId = f.feature._matching_layer_id;
if (layerId === undefined) {
console.error(f)
throw "feature._matching_layer_id is undefined"
if (layerId !== undefined) {
const layer: {
isDisplayed: UIEventSource<boolean>,
layerDef: LayerConfig
} = layerDict[layerId];
if (layer === undefined) {
console.error("No layer found with id ", layerId);
return true;
}
if (FilteringFeatureSource.showLayer(layer, location)) {
return true;
}
}
const layer: {
isDisplayed: UIEventSource<boolean>,
layerDef: LayerConfig
} = layerDict[layerId];
if (layer === undefined) {
throw "No layer found with id " + layerId;
}
if (FilteringFeatureSource.showLayer(layer, location)) {
return true;
}
// Does it match any other layer?
// Does it match any other layer - e.g. because of a switch?
for (const toCheck of layers) {
if (!FilteringFeatureSource.showLayer(toCheck, location)) {
continue;
@ -50,9 +56,7 @@ export default class FilteringFeatureSource implements FeatureSource {
self.features.setData(newFeatures);
}
for (const layer of layers) {
layerDict[layer.layerDef.id] = layer;
}
upstream.features.addCallback(() => {
update()
});

View file

@ -4,7 +4,6 @@ import opening_hours from "opening_hours";
import {And, Or, Tag} from "./Tags";
import {Utils} from "../Utils";
import CountryCoder from "latlon2country"
import {UIEventSource} from "./UIEventSource";
class SimpleMetaTagger {
public readonly keys: string[];
@ -135,7 +134,7 @@ export default class MetaTagging {
}
updateTags();
} catch (e) {
console.error("Error while parsing opening hours of ", tags.id, e);
console.warn("Error while parsing opening hours of ", tags.id, e);
tags["_isOpen"] = "parse_error";
}

View file

@ -100,10 +100,12 @@ export class Changes implements FeatureSource{
}
changes.push({elementId: id, key: kv.key, value: kv.value})
}
State.state.allElements.addOrGetElement(geojson).ping();
console.log("New feature added and pinged")
this.features.data.push({feature:geojson, freshness: new Date()});
this.features.ping();
State.state.allElements.addOrGetElement(geojson).ping();
this.uploadAll([osmNode], changes);
return geojson;

View file

@ -77,7 +77,7 @@ export class UIEventSource<T> {
}
public setData(t: T): UIEventSource<T> {
if (this.data === t) {
if (this.data == t) { // MUST COMPARE BY REFERENCE!
return;
}
this.data = t;
@ -86,8 +86,12 @@ export class UIEventSource<T> {
}
public ping(): void {
const old = this.data;
for (const callback of this._callbacks) {
callback(this.data);
if(this.data === undefined && old !== undefined){
throw "Something undefined the data!"
}
}
}