mapcomplete/UI/Popup/ExportAsGpxViz.ts

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

45 lines
1.7 KiB
TypeScript
Raw Normal View History

2022-11-02 14:44:06 +01:00
import Translations from "../i18n/Translations"
2023-06-02 08:42:08 +02:00
import {SubtleButton} from "../Base/SubtleButton"
2022-11-02 14:44:06 +01:00
import Svg from "../../Svg"
import Combine from "../Base/Combine"
2023-06-02 08:42:08 +02:00
import {GeoOperations} from "../../Logic/GeoOperations"
import {Utils} from "../../Utils"
import {SpecialVisualization, SpecialVisualizationState} from "../SpecialVisualization"
import {UIEventSource} from "../../Logic/UIEventSource"
import {Feature, LineString} from "geojson"
2023-04-20 18:58:31 +02:00
import LayerConfig from "../../Models/ThemeConfig/LayerConfig"
export class ExportAsGpxViz implements SpecialVisualization {
funcName = "export_as_gpx"
docs = "Exports the selected feature as GPX-file"
args = []
2023-04-20 18:58:31 +02:00
constr(
state: SpecialVisualizationState,
tagSource: UIEventSource<Record<string, string>>,
argument: string[],
feature: Feature,
layer: LayerConfig
) {
const t = Translations.t.general.download
2023-04-20 18:58:31 +02:00
if (feature.geometry.type !== "LineString") {
return undefined
}
return new SubtleButton(
Svg.download_svg(),
new Combine([
t.downloadFeatureAsGpx.SetClass("font-bold text-lg"),
t.downloadGpxHelper.SetClass("subtle"),
]).SetClass("flex flex-col")
).onClick(() => {
console.log("Exporting as GPX!")
const tags = tagSource.data
2023-03-28 05:13:48 +02:00
const title = layer.title?.GetRenderValue(tags)?.Subs(tags)?.txt ?? "gpx_track"
2023-04-20 18:58:31 +02:00
const gpx = GeoOperations.toGpx(<Feature<LineString>>feature, title)
2022-11-02 14:44:06 +01:00
Utils.offerContentsAsDownloadableFile(gpx, title + "_mapcomplete_export.gpx", {
mimetype: "{gpx=application/gpx+xml}",
})
})
}
}