| 
									
										
										
										
											2023-04-07 04:23:45 +02:00
										 |  |  | import { FeatureSource, FeatureSourceForLayer } from "../FeatureSource" | 
					
						
							| 
									
										
										
										
											2023-03-28 05:13:48 +02:00
										 |  |  | import { Feature } from "geojson" | 
					
						
							|  |  |  | import { BBox } from "../../BBox" | 
					
						
							|  |  |  | import { GeoOperations } from "../../GeoOperations" | 
					
						
							|  |  |  | import { Store } from "../../UIEventSource" | 
					
						
							|  |  |  | import FilteredLayer from "../../../Models/FilteredLayer" | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /** | 
					
						
							|  |  |  |  * Allows the retrieval of all features in the requested BBox; useful for one-shot queries; | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * Use a ClippedFeatureSource for a continuously updating featuresource | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | export default class GeoIndexedStore implements FeatureSource { | 
					
						
							|  |  |  |     public features: Store<Feature[]> | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     constructor(features: FeatureSource | Store<Feature[]>) { | 
					
						
							|  |  |  |         this.features = features["features"] ?? features | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      * Gets the current features within the given bbox. | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @param bbox | 
					
						
							|  |  |  |      * @constructor | 
					
						
							|  |  |  |      */ | 
					
						
							| 
									
										
										
										
											2023-05-16 03:27:49 +02:00
										 |  |  |     public GetFeaturesWithin(bbox: BBox): Feature[] { | 
					
						
							| 
									
										
										
										
											2023-04-14 00:12:15 +02:00
										 |  |  |         const bboxFeature = bbox.asGeojsonCached() | 
					
						
							| 
									
										
										
										
											2023-04-07 04:23:45 +02:00
										 |  |  |         return this.features.data.filter((f) => { | 
					
						
							|  |  |  |             if (f.geometry.type === "Point") { | 
					
						
							|  |  |  |                 return bbox.contains(<[number, number]>f.geometry.coordinates) | 
					
						
							|  |  |  |             } | 
					
						
							| 
									
										
										
										
											2023-04-14 00:12:15 +02:00
										 |  |  |             if (f.geometry.type === "LineString") { | 
					
						
							|  |  |  |                 const intersection = GeoOperations.intersect( | 
					
						
							|  |  |  |                     BBox.get(f).asGeojsonCached(), | 
					
						
							|  |  |  |                     bboxFeature | 
					
						
							|  |  |  |                 ) | 
					
						
							|  |  |  |                 return intersection !== undefined | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |             if (f.geometry.type === "Polygon" || f.geometry.type === "MultiPolygon") { | 
					
						
							|  |  |  |                 return GeoOperations.intersect(f, bboxFeature) !== undefined | 
					
						
							|  |  |  |             } | 
					
						
							| 
									
										
										
										
											2023-04-07 04:23:45 +02:00
										 |  |  |             return GeoOperations.intersect(f, bboxFeature) !== undefined | 
					
						
							|  |  |  |         }) | 
					
						
							| 
									
										
										
										
											2023-03-28 05:13:48 +02:00
										 |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | export class GeoIndexedStoreForLayer extends GeoIndexedStore implements FeatureSourceForLayer { | 
					
						
							|  |  |  |     readonly layer: FilteredLayer | 
					
						
							|  |  |  |     constructor(features: FeatureSource | Store<Feature[]>, layer: FilteredLayer) { | 
					
						
							|  |  |  |         super(features) | 
					
						
							|  |  |  |         this.layer = layer | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | } |