forked from MapComplete/MapComplete
Remove MapComplete metadata from featurelist
This commit is contained in:
parent
b68bf7b950
commit
bd07eed482
1 changed files with 20 additions and 3 deletions
|
@ -1,14 +1,31 @@
|
||||||
import FeaturePipeline from "../Logic/FeatureSource/FeaturePipeline";
|
import FeaturePipeline from "../Logic/FeatureSource/FeaturePipeline";
|
||||||
import {Utils} from "../Utils";
|
import {Utils} from "../Utils";
|
||||||
|
|
||||||
export function exportAsGeoJson(featurePipeline: FeaturePipeline, options?: {metadata?: boolean}) {
|
export function exportAsGeoJson(featurePipeline: FeaturePipeline, options?: { metadata?: boolean }) {
|
||||||
let defaults = {
|
let defaults = {
|
||||||
metadata: false
|
metadata: false
|
||||||
}
|
}
|
||||||
options = Utils.setDefaults(options, defaults);
|
options = Utils.setDefaults(options, defaults);
|
||||||
// Select all features, ignore the freshness and other data
|
// 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}
|
let geojson = {type: "FeatureCollection", features: featureList}
|
||||||
|
|
||||||
Utils.offerContentsAsDownloadableFile(JSON.stringify(geojson), "Geodata.json");
|
Utils.offerContentsAsDownloadableFile(JSON.stringify(geojson), "Geodata.json");
|
||||||
|
|
Loading…
Reference in a new issue