Small tweaks, better handling in case all goes wrong

This commit is contained in:
pietervdvn 2021-04-23 16:51:44 +02:00
parent 4d5a786e10
commit 127ad9c947
2 changed files with 19 additions and 10 deletions

View file

@ -15,16 +15,21 @@ public readonly name = "FilteringFeatureSource"
const self = this; const self = this;
console.log("INITING pipeline: ",layers)
function update() { function update() {
const layerDict = {}; const layerDict = {};
if(layers.data.length == 0){
throw "No layers defined!"
}
for (const layer of layers.data) { for (const layer of layers.data) {
layerDict[layer.layerDef.id] = layer; layerDict[layer.layerDef.id] = layer;
} }
const features: { feature: any, freshness: Date }[] = upstream.features.data; const features: { feature: any, freshness: Date }[] = upstream.features.data;
const missingLayers = new Set<string>();
const newFeatures = features.filter(f => { const newFeatures = features.filter(f => {
const layerId = f.feature._matching_layer_id; const layerId = f.feature._matching_layer_id;
@ -35,7 +40,7 @@ public readonly name = "FilteringFeatureSource"
layerDef: LayerConfig layerDef: LayerConfig
} = layerDict[layerId]; } = layerDict[layerId];
if (layer === undefined) { if (layer === undefined) {
console.error("No layer found with id ", layerId); missingLayers.add(layerId)
return true; return true;
} }
@ -65,6 +70,9 @@ public readonly name = "FilteringFeatureSource"
}); });
self.features.setData(newFeatures); self.features.setData(newFeatures);
if(missingLayers.size > 0){
console.error("Some layers were not found: ", Array.from(missingLayers))
}
} }

View file

@ -7,16 +7,17 @@ import {GeoOperations} from "../GeoOperations";
* This is the part of the pipeline which introduces extra points at the center of an area (but only if this is demanded by the wayhandling) * This is the part of the pipeline which introduces extra points at the center of an area (but only if this is demanded by the wayhandling)
*/ */
export default class WayHandlingApplyingFeatureSource implements FeatureSource { export default class WayHandlingApplyingFeatureSource implements FeatureSource {
features: UIEventSource<{ feature: any; freshness: Date }[]>; public readonly features: UIEventSource<{ feature: any; freshness: Date }[]>;
public readonly name;
constructor(layers: UIEventSource<{ constructor(layers: UIEventSource<{
layerDef: LayerConfig layerDef: LayerConfig
}[]>, }[]>,
upstream: FeatureSource) { upstream: FeatureSource) {
this.name = "Wayhandling of " + upstream.name;
this.features = upstream.features.map( this.features = upstream.features.map(
features => { features => {
if(features === undefined){ if (features === undefined) {
return; return;
} }
@ -38,7 +39,7 @@ export default class WayHandlingApplyingFeatureSource implements FeatureSource {
throw "No layer found with id " + layerId; throw "No layer found with id " + layerId;
} }
if(layer.wayHandling === LayerConfig.WAYHANDLING_DEFAULT){ if (layer.wayHandling === LayerConfig.WAYHANDLING_DEFAULT) {
newFeatures.push(f); newFeatures.push(f);
continue; continue;
} }
@ -52,9 +53,9 @@ export default class WayHandlingApplyingFeatureSource implements FeatureSource {
// Create the copy // Create the copy
const centerPoint = GeoOperations.centerpoint(feat); const centerPoint = GeoOperations.centerpoint(feat);
centerPoint["_matching_layer_id"] = feat._matching_layer_id; centerPoint["_matching_layer_id"] = feat._matching_layer_id;
newFeatures.push({feature: centerPoint, freshness: f.freshness});
if(layer.wayHandling === LayerConfig.WAYHANDLING_CENTER_AND_WAY){ newFeatures.push({feature: centerPoint, freshness: f.freshness});
if (layer.wayHandling === LayerConfig.WAYHANDLING_CENTER_AND_WAY) {
newFeatures.push(f); newFeatures.push(f);
} }