Add download button to import helper

This commit is contained in:
Pieter Vander Vennet 2022-03-17 11:01:52 +01:00
parent 50d383279d
commit f441eb2f0a
3 changed files with 23 additions and 7 deletions

View file

@ -5,13 +5,17 @@ import Link from "../Base/Link";
import {FixedUiElement} from "../Base/FixedUiElement";
import CheckBoxes from "../Input/Checkboxes";
import Title from "../Base/Title";
import {SubtleButton} from "../Base/SubtleButton";
import Svg from "../../Svg";
import {Utils} from "../../Utils";
import LayerConfig from "../../Models/ThemeConfig/LayerConfig";
export class ConfirmProcess<T> extends Combine implements FlowStep<T> {
export class ConfirmProcess extends Combine implements FlowStep<{ features: any[], layer: LayerConfig }> {
public IsValid: UIEventSource<boolean>
public Value: UIEventSource<T>
public Value: UIEventSource<{ features: any[], layer: LayerConfig }>
constructor(v: T) {
constructor(v: { features: any[], layer: LayerConfig }) {
const toConfirm = [
new Combine(["I have read the ", new Link("import guidelines on the OSM wiki", "https://wiki.openstreetmap.org/wiki/Import_guidelines", true)]),
@ -23,10 +27,21 @@ export class ConfirmProcess<T> extends Combine implements FlowStep<T> {
const licenseClear = new CheckBoxes(toConfirm)
super([
new Title("Did you go through the import process?"),
licenseClear
licenseClear,
new FixedUiElement("Alternatively, you can download the dataset to import directly"),
new SubtleButton(Svg.download_svg(), "Download geojson").OnClickWithLoading("Preparing your download",
async ( ) => {
const geojson = {
type:"FeatureCollection",
features: v.features
}
Utils.offerContentsAsDownloadableFile(JSON.stringify(geojson), "prepared_import_"+v.layer.id+".geojson",{
mimetype: "application/vnd.geo+json"
})
})
]);
this.SetClass("link-underline")
this.IsValid = licenseClear.GetValue().map(selected => toConfirm.length == selected.length)
this.Value = new UIEventSource<T>(v)
this.Value = new UIEventSource<{ features: any[], layer: LayerConfig }>(v)
}
}