| 
									
										
										
										
											2021-01-04 04:06:21 +01:00
										 |  |  | import FeatureSource from "./FeatureSource"; | 
					
						
							|  |  |  | import {UIEventSource} from "../UIEventSource"; | 
					
						
							|  |  |  | import LayerConfig from "../../Customizations/JSON/LayerConfig"; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /** | 
					
						
							|  |  |  |  * In some rare cases, some elements are shown on multiple layers (when 'passthrough' is enabled) | 
					
						
							|  |  |  |  * If this is the case, multiple objects with a different _matching_layer_id are generated. | 
					
						
							| 
									
										
										
										
											2021-03-25 15:19:44 +01:00
										 |  |  |  * In any case, this featureSource marks the objects with _matching_layer_id | 
					
						
							| 
									
										
										
										
											2021-01-04 04:06:21 +01:00
										 |  |  |  */ | 
					
						
							|  |  |  | export default class FeatureDuplicatorPerLayer implements FeatureSource { | 
					
						
							|  |  |  |     public readonly features: UIEventSource<{ feature: any; freshness: Date }[]>; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-04-23 12:55:38 +02:00
										 |  |  |     public readonly name; | 
					
						
							| 
									
										
										
										
											2021-01-04 04:06:21 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-20 01:45:51 +01:00
										 |  |  |     constructor(layers: UIEventSource<{ layerDef: LayerConfig }[]>, upstream: FeatureSource) { | 
					
						
							| 
									
										
										
										
											2021-04-23 12:55:38 +02:00
										 |  |  |         this.name = "FeatureDuplicator of "+upstream.name; | 
					
						
							| 
									
										
										
										
											2021-01-04 04:06:21 +01:00
										 |  |  |         this.features = upstream.features.map(features => { | 
					
						
							|  |  |  |             const newFeatures: { feature: any, freshness: Date }[] = []; | 
					
						
							|  |  |  |             if(features === undefined){ | 
					
						
							|  |  |  |                 return newFeatures; | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |             | 
					
						
							|  |  |  |             for (const f of features) { | 
					
						
							|  |  |  |                 if (f.feature._matching_layer_id) { | 
					
						
							|  |  |  |                     // Already matched previously
 | 
					
						
							|  |  |  |                     // We simply add it
 | 
					
						
							|  |  |  |                     newFeatures.push(f); | 
					
						
							| 
									
										
										
										
											2021-01-04 22:59:11 +01:00
										 |  |  |                     continue; | 
					
						
							| 
									
										
										
										
											2021-01-04 04:06:21 +01:00
										 |  |  |                 } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-04 22:14:56 +01:00
										 |  |  |                  | 
					
						
							|  |  |  |                 let foundALayer = false; | 
					
						
							| 
									
										
										
										
											2021-02-20 01:45:51 +01:00
										 |  |  |                 for (const layer of layers.data) { | 
					
						
							| 
									
										
										
										
											2021-03-20 23:45:52 +01:00
										 |  |  |                     if (layer.layerDef.source.osmTags.matchesProperties(f.feature.properties)) { | 
					
						
							| 
									
										
										
										
											2021-01-04 22:14:56 +01:00
										 |  |  |                         foundALayer = true; | 
					
						
							| 
									
										
										
										
											2021-01-04 04:06:21 +01:00
										 |  |  |                         if (layer.layerDef.passAllFeatures) { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                             // We copy the feature; the "properties" field is kept identical though!
 | 
					
						
							|  |  |  |                             // Keeping "properties" identical is needed, as it might break the 'allElementStorage' otherwise
 | 
					
						
							|  |  |  |                             const newFeature = { | 
					
						
							|  |  |  |                                 geometry: f.feature.geometry, | 
					
						
							|  |  |  |                                 id: f.feature.id, | 
					
						
							|  |  |  |                                 type: f.feature.type, | 
					
						
							|  |  |  |                                 properties: f.feature.properties, | 
					
						
							|  |  |  |                                 _matching_layer_id : layer.layerDef.id | 
					
						
							|  |  |  |                             } | 
					
						
							|  |  |  |                             newFeatures.push({feature: newFeature, freshness: f.freshness}); | 
					
						
							|  |  |  |                         } else { | 
					
						
							|  |  |  |                             // If not 'passAllFeatures', we are done
 | 
					
						
							|  |  |  |                             f.feature._matching_layer_id = layer.layerDef.id; | 
					
						
							|  |  |  |                             newFeatures.push(f); | 
					
						
							|  |  |  |                             break; | 
					
						
							|  |  |  |                         } | 
					
						
							|  |  |  |                     } | 
					
						
							|  |  |  |                 } | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |             return newFeatures; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         }) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | } |