| 
									
										
										
										
											2023-05-05 01:25:12 +02:00
										 |  |  | import {FeatureSource} from "../FeatureSource" | 
					
						
							|  |  |  | import {ImmutableStore, Store} from "../../UIEventSource" | 
					
						
							|  |  |  | import {Feature} from "geojson" | 
					
						
							| 
									
										
										
										
											2021-09-21 01:47:58 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | /** | 
					
						
							| 
									
										
										
										
											2022-06-05 02:24:14 +02:00
										 |  |  |  * A simple, read only feature store. | 
					
						
							| 
									
										
										
										
											2021-09-21 01:47:58 +02:00
										 |  |  |  */ | 
					
						
							| 
									
										
										
										
											2023-05-05 01:25:12 +02:00
										 |  |  | export default class StaticFeatureSource<T extends Feature = Feature> implements FeatureSource<T> { | 
					
						
							|  |  |  |     public readonly features: Store<T[]> | 
					
						
							| 
									
										
										
										
											2021-09-21 01:47:58 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-09-08 21:40:48 +02:00
										 |  |  |     constructor( | 
					
						
							| 
									
										
										
										
											2023-03-23 01:42:47 +01:00
										 |  |  |         features: | 
					
						
							| 
									
										
										
										
											2023-05-05 01:25:12 +02:00
										 |  |  |             | Store<T[]> | 
					
						
							|  |  |  |             | T[] | 
					
						
							|  |  |  |             | { features: T[] } | 
					
						
							|  |  |  |             | { features: Store<T[]> } | 
					
						
							| 
									
										
										
										
											2022-09-08 21:40:48 +02:00
										 |  |  |     ) { | 
					
						
							| 
									
										
										
										
											2022-06-05 02:24:14 +02:00
										 |  |  |         if (features === undefined) { | 
					
						
							| 
									
										
										
										
											2022-02-09 22:37:21 +01:00
										 |  |  |             throw "Static feature source received undefined as source" | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2023-05-05 01:25:12 +02:00
										 |  |  |         let feats: T[] | Store<T[]> | 
					
						
							| 
									
										
										
										
											2023-03-23 01:42:47 +01:00
										 |  |  |         if (features["features"]) { | 
					
						
							|  |  |  |             feats = features["features"] | 
					
						
							|  |  |  |         } else { | 
					
						
							| 
									
										
										
										
											2023-05-05 01:25:12 +02:00
										 |  |  |             feats = <T[] | Store<T[]>>features | 
					
						
							| 
									
										
										
										
											2023-03-23 01:42:47 +01:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2022-06-05 02:24:14 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-03-23 01:42:47 +01:00
										 |  |  |         if (Array.isArray(feats)) { | 
					
						
							|  |  |  |             this.features = new ImmutableStore(feats) | 
					
						
							|  |  |  |         } else { | 
					
						
							|  |  |  |             this.features = feats | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2022-07-08 03:14:55 +02:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-05-05 01:25:12 +02:00
										 |  |  |     public static fromGeojson<T extends Feature>(geojson: T[]): StaticFeatureSource<T> { | 
					
						
							| 
									
										
										
										
											2023-03-23 01:42:47 +01:00
										 |  |  |         return new StaticFeatureSource(geojson) | 
					
						
							| 
									
										
										
										
											2022-06-05 02:24:14 +02:00
										 |  |  |     } | 
					
						
							|  |  |  | } |