| 
									
										
										
										
											2021-01-03 00:19:42 +01:00
										 |  |  | import {UIEventSource} from "../UIEventSource"; | 
					
						
							| 
									
										
										
										
											2021-07-16 01:42:09 +02:00
										 |  |  | import {Utils} from "../../Utils"; | 
					
						
							| 
									
										
										
										
											2021-01-03 00:19:42 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | export default interface FeatureSource { | 
					
						
							| 
									
										
										
										
											2021-07-16 01:42:09 +02:00
										 |  |  |     features: UIEventSource<{ feature: any, freshness: Date }[]>; | 
					
						
							| 
									
										
										
										
											2021-04-23 12:55:38 +02:00
										 |  |  |     /** | 
					
						
							|  |  |  |      * Mainly used for debuging | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     name: string; | 
					
						
							| 
									
										
										
										
											2021-07-16 01:42:09 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | export class FeatureSourceUtils { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      * Exports given featurePipeline as a geojson FeatureLists (downloads as a json) | 
					
						
							|  |  |  |      * @param featurePipeline The FeaturePipeline you want to export | 
					
						
							|  |  |  |      * @param options The options object | 
					
						
							|  |  |  |      * @param options.metadata True if you want to include the MapComplete metadata, false otherwise | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     public static extractGeoJson(featurePipeline: FeatureSource, options: { metadata?: boolean } = {}) { | 
					
						
							|  |  |  |         let defaults = { | 
					
						
							|  |  |  |             metadata: false, | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         options = Utils.setDefaults(options, defaults); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         // Select all features, ignore the freshness and other data
 | 
					
						
							|  |  |  |         let featureList: any[] = featurePipeline.features.data.map((feature) => feature.feature); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         if (!options.metadata) { | 
					
						
							|  |  |  |             for (let i = 0; i < featureList.length; i++) { | 
					
						
							|  |  |  |                 let feature = featureList[i]; | 
					
						
							|  |  |  |                 for (let property in feature.properties) { | 
					
						
							|  |  |  |                     if (property[0] == "_") { | 
					
						
							|  |  |  |                         delete featureList[i]["properties"][property]; | 
					
						
							|  |  |  |                     } | 
					
						
							|  |  |  |                 } | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         return {type: "FeatureCollection", features: featureList} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |    | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-03 00:19:42 +01:00
										 |  |  | } |