| 
									
										
										
										
											2023-06-14 20:39:36 +02:00
										 |  |  | import { FeatureSource, FeatureSourceForLayer } from "../FeatureSource" | 
					
						
							| 
									
										
										
										
											2023-03-28 05:13:48 +02:00
										 |  |  | import StaticFeatureSource from "./StaticFeatureSource" | 
					
						
							| 
									
										
										
										
											2023-06-14 20:39:36 +02:00
										 |  |  | import { BBox } from "../../BBox" | 
					
						
							| 
									
										
										
										
											2023-03-28 05:13:48 +02:00
										 |  |  | import FilteredLayer from "../../../Models/FilteredLayer" | 
					
						
							| 
									
										
										
										
											2023-06-14 20:39:36 +02:00
										 |  |  | import { Store } from "../../UIEventSource" | 
					
						
							|  |  |  | import { Feature } from "geojson" | 
					
						
							| 
									
										
										
										
											2023-03-28 05:13:48 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | /** | 
					
						
							|  |  |  |  * Results in a feature source which has all the elements that touch the given features | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2023-05-05 01:25:12 +02:00
										 |  |  | export default class BBoxFeatureSource<T extends Feature = Feature> extends StaticFeatureSource<T> { | 
					
						
							|  |  |  |     constructor(features: FeatureSource<T>, mustTouch: Store<BBox>) { | 
					
						
							| 
									
										
										
										
											2023-03-28 05:13:48 +02:00
										 |  |  |         super( | 
					
						
							| 
									
										
										
										
											2023-04-27 00:58:21 +02:00
										 |  |  |             features.features.mapD( | 
					
						
							|  |  |  |                 (features) => { | 
					
						
							|  |  |  |                     if (mustTouch.data === undefined) { | 
					
						
							|  |  |  |                         return features | 
					
						
							|  |  |  |                     } | 
					
						
							|  |  |  |                     const box = mustTouch.data | 
					
						
							|  |  |  |                     return features.filter((feature) => { | 
					
						
							|  |  |  |                         if (feature.geometry.type === "Point") { | 
					
						
							|  |  |  |                             return box.contains(<[number, number]>feature.geometry.coordinates) | 
					
						
							|  |  |  |                         } | 
					
						
							|  |  |  |                         return box.overlapsWith(BBox.get(feature)) | 
					
						
							|  |  |  |                     }) | 
					
						
							|  |  |  |                 }, | 
					
						
							|  |  |  |                 [mustTouch] | 
					
						
							| 
									
										
										
										
											2023-03-28 05:13:48 +02:00
										 |  |  |             ) | 
					
						
							|  |  |  |         ) | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-06-14 20:39:36 +02:00
										 |  |  | export class BBoxFeatureSourceForLayer<T extends Feature = Feature> | 
					
						
							|  |  |  |     extends BBoxFeatureSource<T> | 
					
						
							|  |  |  |     implements FeatureSourceForLayer | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2023-04-27 00:58:21 +02:00
										 |  |  |     readonly layer: FilteredLayer | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-05-05 01:25:12 +02:00
										 |  |  |     constructor(features: FeatureSourceForLayer<T>, mustTouch: Store<BBox>) { | 
					
						
							| 
									
										
										
										
											2023-03-28 05:13:48 +02:00
										 |  |  |         super(features, mustTouch) | 
					
						
							|  |  |  |         this.layer = features.layer | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | } |