| 
									
										
										
										
											2022-06-05 02:24:14 +02:00
										 |  |  | import {Store} from "../../Logic/UIEventSource"; | 
					
						
							| 
									
										
										
										
											2022-01-21 01:57:16 +01:00
										 |  |  | import {GeoOperations} from "../../Logic/GeoOperations"; | 
					
						
							| 
									
										
										
										
											2022-07-08 03:14:55 +02:00
										 |  |  | import {Feature, Geometry} from "@turf/turf"; | 
					
						
							| 
									
										
										
										
											2022-01-21 01:57:16 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | export class ImportUtils { | 
					
						
							| 
									
										
										
										
											2022-07-08 03:14:55 +02:00
										 |  |  |     public static partitionFeaturesIfNearby( | 
					
						
							|  |  |  |         toPartitionFeatureCollection: ({ features: Feature<Geometry>[] }), | 
					
						
							|  |  |  |         compareWith: Store<{ features: Feature[] }>, | 
					
						
							|  |  |  |         cutoffDistanceInMeters: Store<number>) | 
					
						
							|  |  |  |         : Store<{ hasNearby: Feature[], noNearby: Feature[] }> { | 
					
						
							| 
									
										
										
										
											2022-01-21 01:57:16 +01:00
										 |  |  |         return compareWith.map(osmData => { | 
					
						
							|  |  |  |             if (osmData?.features === undefined) { | 
					
						
							|  |  |  |                 return undefined | 
					
						
							|  |  |  |             } | 
					
						
							| 
									
										
										
										
											2022-01-26 21:40:38 +01:00
										 |  |  |             if (osmData.features.length === 0) { | 
					
						
							| 
									
										
										
										
											2022-01-22 02:56:35 +01:00
										 |  |  |                 return {noNearby: toPartitionFeatureCollection.features, hasNearby: []} | 
					
						
							|  |  |  |             } | 
					
						
							| 
									
										
										
										
											2022-01-21 01:57:16 +01:00
										 |  |  |             const maxDist = cutoffDistanceInMeters.data | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             const hasNearby = [] | 
					
						
							|  |  |  |             const noNearby = [] | 
					
						
							|  |  |  |             for (const toImportElement of toPartitionFeatureCollection.features) { | 
					
						
							|  |  |  |                 const hasNearbyFeature = osmData.features.some(f => | 
					
						
							| 
									
										
										
										
											2022-07-08 03:14:55 +02:00
										 |  |  |                     maxDist >= GeoOperations.distanceBetween(<any> toImportElement.geometry.coordinates, GeoOperations.centerpointCoordinates(f))) | 
					
						
							| 
									
										
										
										
											2022-01-21 01:57:16 +01:00
										 |  |  |                 if (hasNearbyFeature) { | 
					
						
							|  |  |  |                     hasNearby.push(toImportElement) | 
					
						
							|  |  |  |                 } else { | 
					
						
							|  |  |  |                     noNearby.push(toImportElement) | 
					
						
							|  |  |  |                 } | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             return {hasNearby, noNearby} | 
					
						
							|  |  |  |         }, [cutoffDistanceInMeters]); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | } |