forked from MapComplete/MapComplete
Finishing touches to export functionality, enable it in cycle_infra
This commit is contained in:
parent
e0b71ca53e
commit
13b2c1b572
5 changed files with 100 additions and 15 deletions
|
@ -5,17 +5,49 @@ import State from "../../State";
|
|||
import {FeatureSourceUtils} from "../../Logic/FeatureSource/FeatureSource";
|
||||
import {Utils} from "../../Utils";
|
||||
import Combine from "../Base/Combine";
|
||||
import CheckBoxes from "../Input/Checkboxes";
|
||||
import {GeoOperations} from "../../Logic/GeoOperations";
|
||||
import Toggle from "../Input/Toggle";
|
||||
import Title from "../Base/Title";
|
||||
|
||||
export class ExportDataButton extends Combine {
|
||||
export class ExportDataButton extends Toggle {
|
||||
constructor() {
|
||||
const t = Translations.t.general.download
|
||||
const button = new SubtleButton(Svg.floppy_ui(), t.downloadGeojson.Clone().SetClass("font-bold"))
|
||||
const somethingLoaded = State.state.featurePipeline.features.map(features => features.length > 0);
|
||||
const includeMetaToggle = new CheckBoxes([t.includeMetaData.Clone()])
|
||||
const metaisIncluded = includeMetaToggle.GetValue().map(selected => selected.length > 0)
|
||||
const buttonGeoJson = new SubtleButton(Svg.floppy_ui(),
|
||||
new Combine([t.downloadGeojson.Clone().SetClass("font-bold"),
|
||||
t.downloadGeoJsonHelper.Clone()]).SetClass("flex flex-col"))
|
||||
.onClick(() => {
|
||||
const geojson = FeatureSourceUtils.extractGeoJson(State.state.featurePipeline)
|
||||
const geojson = FeatureSourceUtils.extractGeoJson(State.state.featurePipeline, {metadata: metaisIncluded.data})
|
||||
const name = State.state.layoutToUse.data.id;
|
||||
Utils.offerContentsAsDownloadableFile(JSON.stringify(geojson), `MapComplete_${name}_export_${new Date().toISOString().substr(0,19)}.geojson`);
|
||||
Utils.offerContentsAsDownloadableFile(JSON.stringify(geojson),
|
||||
`MapComplete_${name}_export_${new Date().toISOString().substr(0,19)}.geojson`);
|
||||
})
|
||||
|
||||
super([button, t.licenseInfo.Clone().SetClass("link-underline")])
|
||||
const buttonCSV = new SubtleButton(Svg.floppy_ui(), new Combine(
|
||||
[t.downloadCSV.Clone().SetClass("font-bold"),
|
||||
t.downloadCSVHelper.Clone()]).SetClass("flex flex-col"))
|
||||
.onClick(() => {
|
||||
const geojson = FeatureSourceUtils.extractGeoJson(State.state.featurePipeline, {metadata: metaisIncluded.data})
|
||||
const csv = GeoOperations.toCSV(geojson.features)
|
||||
|
||||
|
||||
Utils.offerContentsAsDownloadableFile(csv,
|
||||
`MapComplete_${name}_export_${new Date().toISOString().substr(0,19)}.csv`,{
|
||||
mimetype:"text/csv"
|
||||
});
|
||||
|
||||
|
||||
})
|
||||
const downloadButtons = new Combine(
|
||||
[new Title(t.title), buttonGeoJson, buttonCSV, includeMetaToggle, t.licenseInfo.Clone().SetClass("link-underline")])
|
||||
.SetClass("w-full flex flex-col border-4 border-gray-300 rounded-3xl p-4")
|
||||
|
||||
super(
|
||||
downloadButtons,
|
||||
t.noDataLoaded.Clone(),
|
||||
somethingLoaded)
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue