| 
									
										
										
										
											2021-01-03 03:09:52 +01:00
										 |  |  | /** | 
					
						
							|  |  |  |  * Every previously added point is remembered, but new points are added | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | import FeatureSource from "./FeatureSource"; | 
					
						
							|  |  |  | import {UIEventSource} from "../UIEventSource"; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-04 22:59:11 +01:00
										 |  |  | export default class RememberingSource implements FeatureSource { | 
					
						
							| 
									
										
										
										
											2021-04-23 12:55:38 +02:00
										 |  |  |     public readonly features: UIEventSource<{ feature: any, freshness: Date }[]>; | 
					
						
							| 
									
										
										
										
											2021-01-04 22:59:11 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-04-23 12:55:38 +02:00
										 |  |  |     public readonly name; | 
					
						
							| 
									
										
										
										
											2021-09-09 00:05:51 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-03 03:09:52 +01:00
										 |  |  |     constructor(source: FeatureSource) { | 
					
						
							|  |  |  |         const self = this; | 
					
						
							| 
									
										
										
										
											2021-09-09 00:05:51 +02:00
										 |  |  |         this.name = "RememberingSource of " + source.name; | 
					
						
							| 
									
										
										
										
											2021-01-04 22:59:11 +01:00
										 |  |  |         const empty = []; | 
					
						
							|  |  |  |         this.features = source.features.map(features => { | 
					
						
							|  |  |  |             const oldFeatures = self.features?.data ?? empty; | 
					
						
							|  |  |  |             if (features === undefined) { | 
					
						
							|  |  |  |                 return oldFeatures; | 
					
						
							| 
									
										
										
										
											2021-01-03 03:09:52 +01:00
										 |  |  |             } | 
					
						
							| 
									
										
										
										
											2021-09-09 00:05:51 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-04 22:59:11 +01:00
										 |  |  |             // Then new ids
 | 
					
						
							| 
									
										
										
										
											2021-06-10 16:55:08 +02:00
										 |  |  |             const ids = new Set<string>(features.map(f => f.feature.properties.id + f.feature.geometry.type + f.feature._matching_layer_id)); | 
					
						
							| 
									
										
										
										
											2021-01-04 22:59:11 +01:00
										 |  |  |             // the old data
 | 
					
						
							| 
									
										
										
										
											2021-06-10 16:55:08 +02:00
										 |  |  |             const oldData = oldFeatures.filter(old => !ids.has(old.feature.properties.id + old.feature.geometry.type + old.feature._matching_layer_id)) | 
					
						
							| 
									
										
										
										
											2021-01-04 22:59:11 +01:00
										 |  |  |             return [...features, ...oldData]; | 
					
						
							| 
									
										
										
										
											2021-01-03 03:09:52 +01:00
										 |  |  |         }) | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2021-01-04 22:59:11 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-03 03:09:52 +01:00
										 |  |  | } |