forked from MapComplete/MapComplete
		
	Huge refactoring of the feature pipeline, WIP
This commit is contained in:
		
							parent
							
								
									7793297348
								
							
						
					
					
						commit
						973b5d8bbe
					
				
					 25 changed files with 522 additions and 591 deletions
				
			
		
							
								
								
									
										32
									
								
								Logic/FeatureSource/Sources/RememberingSource.ts
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										32
									
								
								Logic/FeatureSource/Sources/RememberingSource.ts
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,32 @@ | |||
| 
 | ||||
| import FeatureSource, {FeatureSourceForLayer} from "./FeatureSource"; | ||||
| import {UIEventSource} from "../UIEventSource"; | ||||
| import FilteredLayer from "../../Models/FilteredLayer"; | ||||
| /** | ||||
|  * Every previously added point is remembered, but new points are added. | ||||
|  * Data coming from upstream will always overwrite a previous value | ||||
|  */ | ||||
| export default class RememberingSource implements FeatureSource { | ||||
| 
 | ||||
|     public readonly features: UIEventSource<{ feature: any, freshness: Date }[]>; | ||||
|     public readonly name; | ||||
| 
 | ||||
|     constructor(source: FeatureSource) { | ||||
|         const self = this; | ||||
|         this.name = "RememberingSource of " + source.name; | ||||
|         const empty = []; | ||||
|         this.features = source.features.map(features => { | ||||
|             const oldFeatures = self.features?.data ?? empty; | ||||
|             if (features === undefined) { | ||||
|                 return oldFeatures; | ||||
|             } | ||||
| 
 | ||||
|             // Then new ids
 | ||||
|             const ids = new Set<string>(features.map(f => f.feature.properties.id + f.feature.geometry.type)); | ||||
|             // the old data
 | ||||
|             const oldData = oldFeatures.filter(old => !ids.has(old.feature.properties.id + old.feature.geometry.type)) | ||||
|             return [...features, ...oldData]; | ||||
|         }) | ||||
|     } | ||||
| 
 | ||||
| } | ||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue