Add possibility to upload your travelled track to OSM

This commit is contained in:
Pieter Vander Vennet 2022-08-05 12:39:02 +02:00
parent 9424364f3f
commit 312db3ad50
11 changed files with 208 additions and 44 deletions

View file

@ -61,6 +61,10 @@ import StatisticsPanel from "./BigComponents/StatisticsPanel";
import {OsmFeature} from "../Models/OsmFeature";
import EditableTagRendering from "./Popup/EditableTagRendering";
import TagRenderingConfig from "../Models/ThemeConfig/TagRenderingConfig";
import UploadTraceToOsmUI from "./BigComponents/UploadTraceToOsmUI";
import {Feature} from "geojson";
import {GeoLocationPointProperties} from "../Logic/Actors/GeoLocationHandler";
import {Point} from "@turf/turf";
export interface SpecialVisualization {
funcName: string,
@ -864,7 +868,7 @@ export default class SpecialVisualizations {
const tags = tagSource.data
const feature = state.allElements.ContainingFeatures.get(tags.id)
const matchingLayer = state?.layoutToUse?.getMatchingLayer(tags)
const gpx = GeoOperations.AsGpx(feature, matchingLayer)
const gpx = GeoOperations.AsGpx(feature, {layer: matchingLayer})
const title = matchingLayer.title?.GetRenderValue(tags)?.Subs(tags)?.txt ?? "gpx_track"
Utils.offerContentsAsDownloadableFile(gpx, title + "_mapcomplete_export.gpx", {
mimetype: "{gpx=application/gpx+xml}"
@ -874,6 +878,35 @@ export default class SpecialVisualizations {
})
}
},
{
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() {
const userLocations : Feature<Point, GeoLocationPointProperties>[] = state.historicalUserLocations.features.data.map(f => f.feature)
const trackPoints: string[] = []
for (const l of userLocations) {
let trkpt = ` <trkpt lat="${l.geometry.coordinates[1]}" lon="${l.geometry.coordinates[0]}">`
trkpt += ` <time>${l.properties.date}</time>`
if(l.properties.altitude !== null && l.properties.altitude !== undefined ){
trkpt += ` <ele>${l.properties.altitude}</ele>`
}
trkpt += " </trkpt>"
trackPoints.push(trkpt)
}
const header = '<gpx version="1.1" creator="MapComplete track uploader" xmlns="http://www.topografix.com/GPX/1/1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/gpx.xsd">'
return header+"\n<trk><trkseg>\n"+trackPoints.join("\n")+"\n</trkseg></trk></gpx>"
}
return new UploadTraceToOsmUI(getTrace, state,{
whenUploaded: async () => {
state.historicalUserLocations.features.setData([])
}
})
}
},
{
funcName: "export_as_geojson",
docs: "Exports the selected feature as GeoJson-file",