Remove MapComplete metadata from featurelist

This commit is contained in:
Arno Deceuninck 2021-07-15 09:58:17 +02:00
parent b68bf7b950
commit bd07eed482

View file

@ -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");