2021-01-03 03:09:52 +01:00
|
|
|
import FeatureSource from "./FeatureSource";
|
|
|
|
import {UIEventSource} from "../UIEventSource";
|
|
|
|
import LayerConfig from "../../Customizations/JSON/LayerConfig";
|
|
|
|
import {GeoOperations} from "../GeoOperations";
|
|
|
|
|
2021-03-25 15:19:44 +01:00
|
|
|
/**
|
|
|
|
* 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)
|
|
|
|
*/
|
2021-01-03 03:09:52 +01:00
|
|
|
export default class WayHandlingApplyingFeatureSource implements FeatureSource {
|
2021-04-23 16:51:44 +02:00
|
|
|
public readonly features: UIEventSource<{ feature: any; freshness: Date }[]>;
|
|
|
|
public readonly name;
|
2021-01-03 03:09:52 +01:00
|
|
|
|
2021-02-20 01:45:51 +01:00
|
|
|
constructor(layers: UIEventSource<{
|
2021-01-03 03:09:52 +01:00
|
|
|
layerDef: LayerConfig
|
2021-02-20 01:45:51 +01:00
|
|
|
}[]>,
|
2021-01-03 03:09:52 +01:00
|
|
|
upstream: FeatureSource) {
|
2021-04-23 16:51:44 +02:00
|
|
|
this.name = "Wayhandling of " + upstream.name;
|
2021-01-03 03:09:52 +01:00
|
|
|
this.features = upstream.features.map(
|
|
|
|
features => {
|
2021-04-23 16:51:44 +02:00
|
|
|
if (features === undefined) {
|
2021-01-03 03:09:52 +01:00
|
|
|
return;
|
|
|
|
}
|
2021-02-20 01:45:51 +01:00
|
|
|
|
|
|
|
const layerDict = {};
|
|
|
|
let allDefaultWayHandling = true;
|
|
|
|
for (const layer of layers.data) {
|
|
|
|
layerDict[layer.layerDef.id] = layer;
|
|
|
|
if (layer.layerDef.wayHandling !== LayerConfig.WAYHANDLING_DEFAULT) {
|
|
|
|
allDefaultWayHandling = false;
|
|
|
|
}
|
|
|
|
}
|
2021-04-23 16:51:44 +02:00
|
|
|
|
2021-01-03 03:09:52 +01:00
|
|
|
const newFeatures: { feature: any, freshness: Date }[] = [];
|
|
|
|
for (const f of features) {
|
|
|
|
const feat = f.feature;
|
2021-01-04 04:06:21 +01:00
|
|
|
const layerId = feat._matching_layer_id;
|
2021-01-03 03:09:52 +01:00
|
|
|
const layer: LayerConfig = layerDict[layerId].layerDef;
|
|
|
|
if (layer === undefined) {
|
2021-05-17 17:11:52 +02:00
|
|
|
console.error("No layer found with id " + layerId);
|
|
|
|
continue;
|
2021-01-03 03:09:52 +01:00
|
|
|
}
|
2021-04-23 16:51:44 +02:00
|
|
|
|
|
|
|
if (layer.wayHandling === LayerConfig.WAYHANDLING_DEFAULT) {
|
2021-01-03 03:09:52 +01:00
|
|
|
newFeatures.push(f);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (feat.geometry.type === "Point") {
|
|
|
|
newFeatures.push(f);
|
|
|
|
// it is a point, nothing to do here
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2021-03-25 15:19:44 +01:00
|
|
|
// Create the copy
|
2021-01-03 03:09:52 +01:00
|
|
|
const centerPoint = GeoOperations.centerpoint(feat);
|
2021-04-23 12:55:38 +02:00
|
|
|
centerPoint["_matching_layer_id"] = feat._matching_layer_id;
|
2021-04-23 16:51:44 +02:00
|
|
|
|
2021-01-03 03:09:52 +01:00
|
|
|
newFeatures.push({feature: centerPoint, freshness: f.freshness});
|
2021-04-23 16:51:44 +02:00
|
|
|
if (layer.wayHandling === LayerConfig.WAYHANDLING_CENTER_AND_WAY) {
|
2021-01-03 03:09:52 +01:00
|
|
|
newFeatures.push(f);
|
|
|
|
}
|
2021-04-23 16:51:44 +02:00
|
|
|
|
2021-01-03 03:09:52 +01:00
|
|
|
}
|
|
|
|
return newFeatures;
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|