forked from MapComplete/MapComplete
		
	Updated documentation
This commit is contained in:
		
							parent
							
								
									bd07eed482
								
							
						
					
					
						commit
						e7ef2fb6d8
					
				
					 4 changed files with 19 additions and 13 deletions
				
			
		|  | @ -77,7 +77,7 @@ export default class LayerSelection extends Combine { | |||
|         } | ||||
| 
 | ||||
|         const downloadButton = new SubtleButton("./assets/svg/floppy.svg", "Download visible data as geojson") | ||||
|         downloadButton.onClick(() => exportAsGeoJson(State.state.featurePipeline)) // TODO: Define this
 | ||||
|         downloadButton.onClick(() => exportAsGeoJson(State.state.featurePipeline)) | ||||
|         checkboxes.push(downloadButton) | ||||
| 
 | ||||
|         super(checkboxes) | ||||
|  |  | |||
|  | @ -1,14 +1,25 @@ | |||
| import FeaturePipeline from "../Logic/FeatureSource/FeaturePipeline"; | ||||
| import {Utils} from "../Utils"; | ||||
| 
 | ||||
| export function exportAsGeoJson(featurePipeline: FeaturePipeline, options?: { metadata?: boolean }) { | ||||
| /** | ||||
|  * 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 | ||||
|  */ | ||||
| export function exportAsGeoJson(featurePipeline: FeaturePipeline, options: { metadata?: boolean} = {}) { | ||||
|     let defaults = { | ||||
|         metadata: false | ||||
|         metadata: false, | ||||
|     } | ||||
|     options = Utils.setDefaults(options, defaults); | ||||
| 
 | ||||
|     // Select all features, ignore the freshness and other data
 | ||||
|     let featureList: JSON[] = featurePipeline ? featurePipeline.features.data.map((feature) => feature.feature) : ["I'm empty"]; | ||||
| 
 | ||||
|     /** | ||||
|      * Removes the metadata of MapComplete (all properties starting with an underscore) | ||||
|      * @param featureList JsonList containing features, output object | ||||
|      */ | ||||
|     function removeMetaData(featureList: JSON[]) { | ||||
|         for (let i=0; i < featureList.length; i++) { | ||||
|             let feature = featureList[i]; | ||||
|  | @ -18,13 +29,9 @@ export function exportAsGeoJson(featurePipeline: FeaturePipeline, options?: { me | |||
|                 } | ||||
|             } | ||||
|         } | ||||
|         return featureList; | ||||
|     } | ||||
| 
 | ||||
|     // Remove the metadata of MapComplete (all properties starting with an underscore)
 | ||||
|     if (!options.metadata) { | ||||
|         removeMetaData(featureList); | ||||
|     } | ||||
|     if (!options.metadata) removeMetaData(featureList); | ||||
| 
 | ||||
|     let geojson = {type: "FeatureCollection", features: featureList} | ||||
| 
 | ||||
|  |  | |||
							
								
								
									
										7
									
								
								Utils.ts
									
										
									
									
									
								
							
							
						
						
									
										7
									
								
								Utils.ts
									
										
									
									
									
								
							|  | @ -449,11 +449,10 @@ export class Utils { | |||
|     } | ||||
| 
 | ||||
|     public static setDefaults(options, defaults){ | ||||
|         let result = {}; | ||||
|         for (let key of defaults){ | ||||
|             result[key] = key in options ? options[key] : defaults[key]; | ||||
|         for (let key in defaults){ | ||||
|             if (!(key in options)) options[key] = defaults[key]; | ||||
|         } | ||||
|         return result; | ||||
|         return options; | ||||
|     } | ||||
| } | ||||
| 
 | ||||
|  |  | |||
|  | @ -1,5 +1,5 @@ | |||
| { | ||||
|     "defaultSeverity": "error", | ||||
|     "defaultSeverity": "warn", | ||||
|     "extends": [ | ||||
|         "tslint:recommended", | ||||
|         "tslint-no-circular-imports" | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue