forked from MapComplete/MapComplete
		
	Fixing adding multiple points
This commit is contained in:
		
							parent
							
								
									32bc1433b4
								
							
						
					
					
						commit
						baf41cb79d
					
				
					 6 changed files with 20 additions and 25 deletions
				
			
		|  | @ -13,27 +13,18 @@ export default class FeatureDuplicatorPerLayer implements FeatureSource { | |||
| 
 | ||||
| 
 | ||||
|     constructor(layers: { layerDef: LayerConfig }[], upstream: FeatureSource) { | ||||
|         let noPassthroughts = true; | ||||
|         for (const layer of layers) { | ||||
|             if (layer.layerDef.passAllFeatures) { | ||||
|                 noPassthroughts = false; | ||||
|                 break; | ||||
|             } | ||||
|         } | ||||
| 
 | ||||
|         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); | ||||
|                     return; | ||||
|                     continue; | ||||
|                 } | ||||
| 
 | ||||
|                  | ||||
|  |  | |||
|  | @ -17,6 +17,9 @@ export default class FeatureSourceMerger implements FeatureSource { | |||
|     private Update() { | ||||
|         let all = {}; // Mapping 'id' -> {feature, freshness}
 | ||||
|         for (const source of this._sources) { | ||||
|             if(source?.features?.data === undefined){ | ||||
|                 continue; | ||||
|             } | ||||
|             for (const f of source.features.data) { | ||||
|                 const id = f.feature.properties.id+f.feature.geometry.type+f.feature._matching_layer_id; | ||||
|                 const oldV = all[id]; | ||||
|  |  | |||
|  | @ -4,21 +4,24 @@ | |||
| import FeatureSource from "./FeatureSource"; | ||||
| import {UIEventSource} from "../UIEventSource"; | ||||
| 
 | ||||
| export default class RememberingSource implements FeatureSource{ | ||||
|     features: UIEventSource<{feature: any, freshness: Date}[]> = new UIEventSource<{feature: any, freshness: Date}[]>([]); | ||||
|      | ||||
| export default class RememberingSource implements FeatureSource { | ||||
|     features: UIEventSource<{ feature: any, freshness: Date }[]>; | ||||
| 
 | ||||
|     constructor(source: FeatureSource) { | ||||
|         const self = this; | ||||
|         source.features.addCallbackAndRun(features => { | ||||
|             if(features === undefined){ | ||||
|                 return; | ||||
|         const empty = []; | ||||
|         this.features = source.features.map(features => { | ||||
|             const oldFeatures = self.features?.data ?? empty; | ||||
|             if (features === undefined) { | ||||
|                 return oldFeatures; | ||||
|             } | ||||
|             const ids = new Set<string>( features.map(f => f.feature.properties.id+f.feature.geometry.type)); | ||||
|             const newList = features.concat( | ||||
|                 self.features.data.filter(old => !ids.has(old.feature.properties.id+old.feature.geometry.type)) | ||||
|             ) | ||||
|             self.features.setData(newList); | ||||
|             | ||||
|             // 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