forked from MapComplete/MapComplete
		
	More work on splitting roads, WIP; refactoring tests
This commit is contained in:
		
							parent
							
								
									e374bb355c
								
							
						
					
					
						commit
						1f93923820
					
				
					 62 changed files with 1163 additions and 823 deletions
				
			
		|  | @ -1,4 +1,4 @@ | |||
| import FeatureSource, {FeatureSourceForLayer} from "./FeatureSource"; | ||||
| import FeatureSource, {FeatureSourceForLayer, Tiled} from "./FeatureSource"; | ||||
| import {UIEventSource} from "../UIEventSource"; | ||||
| import FilteredLayer from "../../Models/FilteredLayer"; | ||||
| import SimpleFeatureSource from "./Sources/SimpleFeatureSource"; | ||||
|  | @ -12,10 +12,13 @@ import SimpleFeatureSource from "./Sources/SimpleFeatureSource"; | |||
| export default class PerLayerFeatureSourceSplitter { | ||||
| 
 | ||||
|     constructor(layers: UIEventSource<FilteredLayer[]>, | ||||
|                 handleLayerData: (source: FeatureSourceForLayer) => void, | ||||
|                 upstream: FeatureSource) { | ||||
|                 handleLayerData: (source: FeatureSourceForLayer & Tiled) => void, | ||||
|                 upstream: FeatureSource, | ||||
|                 options?:{ | ||||
|         handleLeftovers?: (featuresWithoutLayer: any[]) => void | ||||
|                 }) { | ||||
| 
 | ||||
|         const knownLayers = new Map<string, FeatureSourceForLayer>() | ||||
|         const knownLayers = new Map<string, FeatureSourceForLayer & Tiled>() | ||||
| 
 | ||||
|         function update() { | ||||
|             const features = upstream.features.data; | ||||
|  | @ -30,7 +33,7 @@ export default class PerLayerFeatureSourceSplitter { | |||
|             // Note that this splitter is only run when it is invoked by the overpass feature source, so we can't be sure in which layer it should go
 | ||||
| 
 | ||||
|             const featuresPerLayer = new Map<string, { feature, freshness } []>(); | ||||
| 
 | ||||
|             const noLayerFound = [] | ||||
|             function addTo(layer: FilteredLayer, feature: { feature, freshness }) { | ||||
|                 const id = layer.layerDef.id | ||||
|                 const list = featuresPerLayer.get(id) | ||||
|  | @ -51,6 +54,7 @@ export default class PerLayerFeatureSourceSplitter { | |||
|                             break; | ||||
|                         } | ||||
|                     } | ||||
|                     noLayerFound.push(f) | ||||
|                 } | ||||
|             } | ||||
| 
 | ||||
|  | @ -75,6 +79,11 @@ export default class PerLayerFeatureSourceSplitter { | |||
|                     featureSource.features.setData(features) | ||||
|                 } | ||||
|             } | ||||
|              | ||||
|             // AT last, the leftovers are handled
 | ||||
|             if(options?.handleLeftovers !== undefined && noLayerFound.length > 0){ | ||||
|                 options.handleLeftovers(noLayerFound) | ||||
|             } | ||||
|         } | ||||
| 
 | ||||
|         layers.addCallback(_ => update()) | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue