import { Utils } from "../../Utils" import { Feature } from "geojson" import { Point } from "@turf/turf" import { GeoLocationPointProperties } from "../../Logic/State/GeoLocationState" import UploadTraceToOsmUI from "../BigComponents/UploadTraceToOsmUI" import { SpecialVisualization } from "../SpecialVisualization" /** * Wrapper around 'UploadTraceToOsmUI' */ export class UploadToOsmViz implements SpecialVisualization { funcName = "upload_to_osm" docs = "Uploads the GPS-history as GPX to OpenStreetMap.org; clears the history afterwards. The actual feature is ignored." args = [] constr(state, featureTags, args) { function getTrace(title: string) { title = title?.trim() if (title === undefined || title === "") { title = "Uploaded with MapComplete" } title = Utils.EncodeXmlValue(title) const userLocations: Feature[] = state.historicalUserLocations.features.data.map((f) => f.feature) const trackPoints: string[] = [] for (const l of userLocations) { let trkpt = ` ` trkpt += ` ` if (l.properties.altitude !== null && l.properties.altitude !== undefined) { trkpt += ` ${l.properties.altitude}` } trkpt += " " trackPoints.push(trkpt) } const header = '' return ( header + "\n" + title + "\n\n" + trackPoints.join("\n") + "\n" ) } return new UploadTraceToOsmUI(getTrace, state, { whenUploaded: async () => { state.historicalUserLocations.features.setData([]) }, }) } }