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