| 
									
										
										
										
											2022-06-05 02:24:14 +02:00
										 |  |  | import FeatureSource, {FeatureSourceForLayer, Tiled} from "../FeatureSource"; | 
					
						
							|  |  |  | import {ImmutableStore, Store, UIEventSource} from "../../UIEventSource"; | 
					
						
							|  |  |  | import {stat} from "fs"; | 
					
						
							|  |  |  | import FilteredLayer from "../../../Models/FilteredLayer"; | 
					
						
							|  |  |  | import {BBox} from "../../BBox"; | 
					
						
							| 
									
										
										
										
											2022-07-08 03:14:55 +02:00
										 |  |  | import {Feature} from "@turf/turf"; | 
					
						
							| 
									
										
										
										
											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
										 |  |  |  */ | 
					
						
							|  |  |  | export default class StaticFeatureSource implements FeatureSource { | 
					
						
							| 
									
										
										
										
											2022-06-05 02:24:14 +02:00
										 |  |  |     public readonly features: Store<{ feature: any; freshness: Date }[]>; | 
					
						
							|  |  |  |     public readonly name: string | 
					
						
							| 
									
										
										
										
											2021-09-21 01:47:58 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-07-08 03:14:55 +02:00
										 |  |  |     constructor(features: Store<{ feature: Feature, freshness: Date }[]>, name = "StaticFeatureSource") { | 
					
						
							| 
									
										
										
										
											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" | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2022-06-05 02:24:14 +02:00
										 |  |  |         this.name = name; | 
					
						
							|  |  |  |         this.features = features; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-07-08 03:14:55 +02:00
										 |  |  |     public static fromGeojsonAndDate(features: { feature: Feature, freshness: Date }[], name = "StaticFeatureSourceFromGeojsonAndDate"): StaticFeatureSource { | 
					
						
							| 
									
										
										
										
											2022-06-05 02:24:14 +02:00
										 |  |  |         return new StaticFeatureSource(new ImmutableStore(features), name); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-07-08 03:14:55 +02:00
										 |  |  |     public static fromGeojson(geojson: Feature[], name = "StaticFeatureSourceFromGeojson"): StaticFeatureSource { | 
					
						
							| 
									
										
										
										
											2022-06-05 02:24:14 +02:00
										 |  |  |         const now = new Date(); | 
					
						
							|  |  |  |         return StaticFeatureSource.fromGeojsonAndDate(geojson.map(feature => ({feature, freshness: now})), name); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-07-08 03:14:55 +02:00
										 |  |  |     public static fromGeojsonStore(geojson: Store<Feature[]>, name = "StaticFeatureSourceFromGeojson"): StaticFeatureSource { | 
					
						
							|  |  |  |         const now = new Date(); | 
					
						
							|  |  |  |         const mapped : Store<{feature: Feature, freshness: Date}[]> = geojson.map(features => features.map(feature => ({feature, freshness: now}))) | 
					
						
							|  |  |  |         return new StaticFeatureSource(mapped, name); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     static fromDateless(featureSource: Store<{ feature: Feature }[]>, name = "StaticFeatureSourceFromDateless") { | 
					
						
							| 
									
										
										
										
											2022-06-05 02:24:14 +02:00
										 |  |  |         const now = new Date(); | 
					
						
							|  |  |  |         return new StaticFeatureSource(featureSource.map(features => features.map(feature => ({ | 
					
						
							|  |  |  |             feature: feature.feature, | 
					
						
							|  |  |  |             freshness: now | 
					
						
							|  |  |  |         }))), name); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | export class TiledStaticFeatureSource extends StaticFeatureSource implements Tiled, FeatureSourceForLayer{ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     public readonly bbox: BBox = BBox.global; | 
					
						
							|  |  |  |     public readonly tileIndex: number;    | 
					
						
							|  |  |  |     public readonly layer: FilteredLayer; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     constructor(features: Store<{ feature: any, freshness: Date }[]>, layer: FilteredLayer ,tileIndex : number = 0) { | 
					
						
							|  |  |  |         super(features); | 
					
						
							|  |  |  |         this.tileIndex = tileIndex ; | 
					
						
							|  |  |  |         this.layer=  layer; | 
					
						
							|  |  |  |         this.bbox = BBox.fromTileIndex(this.tileIndex) | 
					
						
							| 
									
										
										
										
											2021-09-21 01:47:58 +02:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-06-05 02:24:14 +02:00
										 |  |  | } |