diff --git a/UI/GeoJsonExport.ts b/UI/GeoJsonExport.ts index c18baed17..68037eee3 100644 --- a/UI/GeoJsonExport.ts +++ b/UI/GeoJsonExport.ts @@ -1,14 +1,31 @@ import FeaturePipeline from "../Logic/FeatureSource/FeaturePipeline"; import {Utils} from "../Utils"; -export function exportAsGeoJson(featurePipeline: FeaturePipeline, options?: {metadata?: boolean}) { +export function exportAsGeoJson(featurePipeline: FeaturePipeline, options?: { metadata?: boolean }) { let defaults = { metadata: false } options = Utils.setDefaults(options, defaults); // Select all features, ignore the freshness and other data - // TODO: Remove mapcomplete metadata (starting with underscore) - let featureList: JSON[] = featurePipeline? featurePipeline.features.data.map((feature) => feature.feature) : ["I'm empty"]; + let featureList: JSON[] = featurePipeline ? featurePipeline.features.data.map((feature) => feature.feature) : ["I'm empty"]; + + function removeMetaData(featureList: JSON[]) { + 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 featureList; + } + + // Remove the metadata of MapComplete (all properties starting with an underscore) + if (!options.metadata) { + removeMetaData(featureList); + } + let geojson = {type: "FeatureCollection", features: featureList} Utils.offerContentsAsDownloadableFile(JSON.stringify(geojson), "Geodata.json");