forked from MapComplete/MapComplete
More refactoring: using a decent, configurable datapipeline now
This commit is contained in:
parent
6ac8ec84e4
commit
e42a668c4a
17 changed files with 434 additions and 265 deletions
66
Logic/FeatureSource/WayHandlingApplyingFeatureSource.ts
Normal file
66
Logic/FeatureSource/WayHandlingApplyingFeatureSource.ts
Normal file
|
@ -0,0 +1,66 @@
|
|||
import FeatureSource from "./FeatureSource";
|
||||
import {UIEventSource} from "../UIEventSource";
|
||||
import LayerConfig from "../../Customizations/JSON/LayerConfig";
|
||||
import {GeoOperations} from "../GeoOperations";
|
||||
|
||||
export default class WayHandlingApplyingFeatureSource implements FeatureSource {
|
||||
features: UIEventSource<{ feature: any; freshness: Date }[]>;
|
||||
|
||||
constructor(layers: {
|
||||
layerDef: LayerConfig
|
||||
}[],
|
||||
upstream: FeatureSource) {
|
||||
const layerDict = {};
|
||||
let allDefaultWayHandling = true;
|
||||
for (const layer of layers) {
|
||||
layerDict[layer.layerDef.id] = layer;
|
||||
if (layer.layerDef.wayHandling !== LayerConfig.WAYHANDLING_DEFAULT) {
|
||||
allDefaultWayHandling = false;
|
||||
}
|
||||
}
|
||||
if (allDefaultWayHandling) {
|
||||
this.features = upstream.features;
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
this.features = upstream.features.map(
|
||||
features => {
|
||||
if(features === undefined){
|
||||
return;
|
||||
}
|
||||
const newFeatures: { feature: any, freshness: Date }[] = [];
|
||||
for (const f of features) {
|
||||
const feat = f.feature;
|
||||
const layerId = feat.properties._matching_layer_id;
|
||||
const layer: LayerConfig = layerDict[layerId].layerDef;
|
||||
if (layer === undefined) {
|
||||
throw "No layer found with id " + layerId;
|
||||
}
|
||||
|
||||
if(layer.wayHandling === LayerConfig.WAYHANDLING_DEFAULT){
|
||||
newFeatures.push(f);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (feat.geometry.type === "Point") {
|
||||
newFeatures.push(f);
|
||||
// it is a point, nothing to do here
|
||||
continue;
|
||||
}
|
||||
|
||||
const centerPoint = GeoOperations.centerpoint(feat);
|
||||
newFeatures.push({feature: centerPoint, freshness: f.freshness});
|
||||
|
||||
if(layer.wayHandling === LayerConfig.WAYHANDLING_CENTER_AND_WAY){
|
||||
newFeatures.push(f);
|
||||
}
|
||||
|
||||
}
|
||||
return newFeatures;
|
||||
}
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue