| 
									
										
										
										
											2021-10-22 18:53:07 +02:00
										 |  |  | /** | 
					
						
							|  |  |  |  * This feature source helps the ShowDataLayer class: it introduces the necessary extra features and indiciates with what renderConfig it should be rendered. | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | import {UIEventSource} from "../../UIEventSource"; | 
					
						
							|  |  |  | import {GeoOperations} from "../../GeoOperations"; | 
					
						
							|  |  |  | import FeatureSource from "../FeatureSource"; | 
					
						
							|  |  |  | import PointRenderingConfig from "../../../Models/ThemeConfig/PointRenderingConfig"; | 
					
						
							|  |  |  | import LayerConfig from "../../../Models/ThemeConfig/LayerConfig"; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | export default class RenderingMultiPlexerFeatureSource { | 
					
						
							|  |  |  |     public readonly features: UIEventSource<(any & { pointRenderingIndex: number | undefined, lineRenderingIndex: number | undefined })[]>; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     constructor(upstream: FeatureSource, layer: LayerConfig) { | 
					
						
							|  |  |  |         this.features = upstream.features.map( | 
					
						
							|  |  |  |             features => { | 
					
						
							|  |  |  |                 if (features === undefined) { | 
					
						
							|  |  |  |                     return; | 
					
						
							|  |  |  |                 } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                 const pointRenderObjects: { rendering: PointRenderingConfig, index: number }[] = layer.mapRendering.map((r, i) => ({ | 
					
						
							|  |  |  |                     rendering: r, | 
					
						
							|  |  |  |                     index: i | 
					
						
							|  |  |  |                 })) | 
					
						
							|  |  |  |                 const pointRenderings = pointRenderObjects.filter(r => r.rendering.location.has("point")) | 
					
						
							|  |  |  |                 const centroidRenderings = pointRenderObjects.filter(r => r.rendering.location.has("centroid")) | 
					
						
							|  |  |  |                 const startRenderings = pointRenderObjects.filter(r => r.rendering.location.has("start")) | 
					
						
							|  |  |  |                 const endRenderings = pointRenderObjects.filter(r => r.rendering.location.has("end")) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                 const lineRenderObjects = layer.lineRendering | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-11-09 18:41:20 +01:00
										 |  |  |                 const withIndex: (any & { pointRenderingIndex: number | undefined, lineRenderingIndex: number | undefined, multiLineStringIndex: number | undefined })[] = []; | 
					
						
							| 
									
										
										
										
											2021-10-22 18:53:07 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-11-07 16:34:51 +01:00
										 |  |  |                 function addAsPoint(feat, rendering, coordinate) { | 
					
						
							| 
									
										
										
										
											2021-10-22 18:53:07 +02:00
										 |  |  |                     const patched = { | 
					
						
							|  |  |  |                         ...feat, | 
					
						
							|  |  |  |                         pointRenderingIndex: rendering.index | 
					
						
							|  |  |  |                     } | 
					
						
							|  |  |  |                     patched.geometry = { | 
					
						
							|  |  |  |                         type: "Point", | 
					
						
							|  |  |  |                         coordinates: coordinate | 
					
						
							|  |  |  |                     } | 
					
						
							|  |  |  |                     withIndex.push(patched) | 
					
						
							|  |  |  |                 } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                 for (const f of features) { | 
					
						
							|  |  |  |                     const feat = f.feature; | 
					
						
							|  |  |  |                     if (feat.geometry.type === "Point") { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                         for (const rendering of pointRenderings) { | 
					
						
							|  |  |  |                             withIndex.push({ | 
					
						
							|  |  |  |                                 ...feat, | 
					
						
							|  |  |  |                                 pointRenderingIndex: rendering.index | 
					
						
							|  |  |  |                             }) | 
					
						
							|  |  |  |                         } | 
					
						
							|  |  |  |                     } else { | 
					
						
							| 
									
										
										
										
											2021-11-09 23:44:20 +01:00
										 |  |  |                         // This is a a line: add the centroids
 | 
					
						
							| 
									
										
										
										
											2021-10-22 18:53:07 +02:00
										 |  |  |                         for (const rendering of centroidRenderings) { | 
					
						
							|  |  |  |                             addAsPoint(feat, rendering, GeoOperations.centerpointCoordinates(feat)) | 
					
						
							|  |  |  |                         } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-11-09 23:44:20 +01:00
										 |  |  |                         if (feat.geometry.type === "LineString") { | 
					
						
							| 
									
										
										
										
											2021-11-16 15:50:26 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-11-09 23:44:20 +01:00
										 |  |  |                             // Add start- and endpoints
 | 
					
						
							| 
									
										
										
										
											2021-10-22 18:53:07 +02:00
										 |  |  |                             const coordinates = feat.geometry.coordinates | 
					
						
							|  |  |  |                             for (const rendering of startRenderings) { | 
					
						
							|  |  |  |                                 addAsPoint(feat, rendering, coordinates[0]) | 
					
						
							|  |  |  |                             } | 
					
						
							|  |  |  |                             for (const rendering of endRenderings) { | 
					
						
							|  |  |  |                                 const coordinate = coordinates[coordinates.length - 1] | 
					
						
							|  |  |  |                                 addAsPoint(feat, rendering, coordinate) | 
					
						
							|  |  |  |                             } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-11-16 15:50:26 +01:00
										 |  |  |                         } | 
					
						
							| 
									
										
										
										
											2021-11-09 23:44:20 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-11-16 15:50:26 +01:00
										 |  |  |                         // AT last, add it 'as is' to what we should render 
 | 
					
						
							|  |  |  |                         for (let i = 0; i < lineRenderObjects.length; i++) { | 
					
						
							|  |  |  |                             withIndex.push({ | 
					
						
							|  |  |  |                                 ...feat, | 
					
						
							|  |  |  |                                 lineRenderingIndex: i | 
					
						
							|  |  |  |                             }) | 
					
						
							| 
									
										
										
										
											2021-10-22 18:53:07 +02:00
										 |  |  |                         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                     } | 
					
						
							|  |  |  |                 } | 
					
						
							| 
									
										
										
										
											2021-11-09 18:41:20 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-10-22 18:53:07 +02:00
										 |  |  |                 return withIndex; | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         ); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | } |