forked from MapComplete/MapComplete
Fix hiding and showing of features
This commit is contained in:
parent
d4f107c81a
commit
bc1863dcb6
12 changed files with 160 additions and 137 deletions
|
@ -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;
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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()
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue