Some finetuning of GPX trace uploading
This commit is contained in:
parent
312db3ad50
commit
06b5df833f
4 changed files with 43 additions and 29 deletions
|
@ -8,8 +8,6 @@ import Img from "../../UI/Base/Img";
|
||||||
import {Utils} from "../../Utils";
|
import {Utils} from "../../Utils";
|
||||||
import {OsmObject} from "./OsmObject";
|
import {OsmObject} from "./OsmObject";
|
||||||
import {Changes} from "./Changes";
|
import {Changes} from "./Changes";
|
||||||
import {GeoOperations} from "../GeoOperations";
|
|
||||||
import { Feature } from "@turf/turf";
|
|
||||||
|
|
||||||
export default class UserDetails {
|
export default class UserDetails {
|
||||||
|
|
||||||
|
|
|
@ -17,7 +17,7 @@ export default class UploadTraceToOsmUI extends Toggle {
|
||||||
|
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
trace: () => string,
|
trace: (title: string) => string,
|
||||||
state: {
|
state: {
|
||||||
layoutToUse: LayoutConfig;
|
layoutToUse: LayoutConfig;
|
||||||
osmConnection: OsmConnection
|
osmConnection: OsmConnection
|
||||||
|
@ -25,7 +25,7 @@ export default class UploadTraceToOsmUI extends Toggle {
|
||||||
whenUploaded?: () => void | Promise<void>
|
whenUploaded?: () => void | Promise<void>
|
||||||
}) {
|
}) {
|
||||||
const t = Translations.t.general.uploadGpx
|
const t = Translations.t.general.uploadGpx
|
||||||
|
const uploadFinished = new UIEventSource(false)
|
||||||
const traceVisibilities: {
|
const traceVisibilities: {
|
||||||
key: "private" | "public",
|
key: "private" | "public",
|
||||||
name: Translation,
|
name: Translation,
|
||||||
|
@ -33,11 +33,11 @@ export default class UploadTraceToOsmUI extends Toggle {
|
||||||
}[] = [
|
}[] = [
|
||||||
{
|
{
|
||||||
key: "private",
|
key: "private",
|
||||||
...Translations.t.general.uploadGpx.modes.private
|
...t.modes.private
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
key: "public",
|
key: "public",
|
||||||
...Translations.t.general.uploadGpx.modes.public
|
...t.modes.public
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|
||||||
|
@ -52,7 +52,10 @@ export default class UploadTraceToOsmUI extends Toggle {
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
const description = new TextField({
|
const description = new TextField({
|
||||||
placeholder: t.placeHolder
|
placeholder: t.meta.descriptionPlaceHolder
|
||||||
|
})
|
||||||
|
const title = new TextField({
|
||||||
|
placeholder: t.meta.titlePlaceholder
|
||||||
})
|
})
|
||||||
const clicked = new UIEventSource<boolean>(false)
|
const clicked = new UIEventSource<boolean>(false)
|
||||||
|
|
||||||
|
@ -63,15 +66,17 @@ export default class UploadTraceToOsmUI extends Toggle {
|
||||||
|
|
||||||
t.choosePermission,
|
t.choosePermission,
|
||||||
dropdown,
|
dropdown,
|
||||||
new Title(t.description.title, 4),
|
new Title(t.meta.title, 4),
|
||||||
t.description.intro,
|
t.meta.intro,
|
||||||
|
title,
|
||||||
|
t.meta.descriptionIntro,
|
||||||
description,
|
description,
|
||||||
new Combine([
|
new Combine([
|
||||||
new SubtleButton(Svg.close_svg(), Translations.t.general.cancel).onClick(() => {
|
new SubtleButton(Svg.close_svg(), Translations.t.general.cancel).onClick(() => {
|
||||||
clicked.setData(false)
|
clicked.setData(false)
|
||||||
}).SetClass(""),
|
}).SetClass(""),
|
||||||
new SubtleButton(Svg.upload_svg(), t.confirm).OnClickWithLoading(t.uploading, async () => {
|
new SubtleButton(Svg.upload_svg(), t.confirm).OnClickWithLoading(t.uploading, async () => {
|
||||||
await state?.osmConnection?.uploadGpxTrack(trace(), {
|
await state?.osmConnection?.uploadGpxTrack(trace(title.GetValue().data), {
|
||||||
visibility: dropdown.GetValue().data,
|
visibility: dropdown.GetValue().data,
|
||||||
description: description.GetValue().data,
|
description: description.GetValue().data,
|
||||||
labels: ["MapComplete", state?.layoutToUse?.id]
|
labels: ["MapComplete", state?.layoutToUse?.id]
|
||||||
|
@ -80,17 +85,20 @@ export default class UploadTraceToOsmUI extends Toggle {
|
||||||
if (options?.whenUploaded !== undefined) {
|
if (options?.whenUploaded !== undefined) {
|
||||||
await options.whenUploaded()
|
await options.whenUploaded()
|
||||||
}
|
}
|
||||||
|
uploadFinished.setData(true)
|
||||||
|
|
||||||
}).SetClass("")
|
})
|
||||||
]).SetClass("flex flex-wrap flex-wrap-reverse justify-between items-stretch")
|
]).SetClass("flex flex-wrap flex-wrap-reverse justify-between items-stretch")
|
||||||
]).SetClass("flex flex-col p-4 rounded border-2 m-2 border-subtle")
|
]).SetClass("flex flex-col p-4 rounded border-2 m-2 border-subtle")
|
||||||
|
|
||||||
|
|
||||||
super(
|
super(
|
||||||
|
new Combine([Svg.confirm_svg(),t.uploadFinished]).SetClass("flex"),
|
||||||
|
new Toggle(
|
||||||
confirmPanel,
|
confirmPanel,
|
||||||
new SubtleButton(Svg.upload_svg(), t.title)
|
new SubtleButton(Svg.upload_svg(), t.title)
|
||||||
.onClick(() => clicked.setData(true)),
|
.onClick(() => clicked.setData(true)),
|
||||||
clicked
|
clicked
|
||||||
)
|
), uploadFinished)
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -881,26 +881,31 @@ export default class SpecialVisualizations {
|
||||||
{
|
{
|
||||||
funcName: "upload_to_osm",
|
funcName: "upload_to_osm",
|
||||||
docs: "Uploads the GPS-history as GPX to OpenStreetMap.org; clears the history afterwards. The actual feature is ignored.",
|
docs: "Uploads the GPS-history as GPX to OpenStreetMap.org; clears the history afterwards. The actual feature is ignored.",
|
||||||
args:[],
|
args: [],
|
||||||
constr(state, featureTags, args) {
|
constr(state, featureTags, args) {
|
||||||
|
|
||||||
function getTrace() {
|
function getTrace(title: string) {
|
||||||
const userLocations : Feature<Point, GeoLocationPointProperties>[] = state.historicalUserLocations.features.data.map(f => f.feature)
|
title = title?.trim()
|
||||||
|
if (title === undefined || title === "") {
|
||||||
|
title = "Uploaded with MapComplete"
|
||||||
|
}
|
||||||
|
title = Utils.EncodeXmlValue(title)
|
||||||
|
const userLocations: Feature<Point, GeoLocationPointProperties>[] = state.historicalUserLocations.features.data.map(f => f.feature)
|
||||||
const trackPoints: string[] = []
|
const trackPoints: string[] = []
|
||||||
for (const l of userLocations) {
|
for (const l of userLocations) {
|
||||||
let trkpt = ` <trkpt lat="${l.geometry.coordinates[1]}" lon="${l.geometry.coordinates[0]}">`
|
let trkpt = ` <trkpt lat="${l.geometry.coordinates[1]}" lon="${l.geometry.coordinates[0]}">`
|
||||||
trkpt += ` <time>${l.properties.date}</time>`
|
trkpt += ` <time>${l.properties.date}</time>`
|
||||||
if(l.properties.altitude !== null && l.properties.altitude !== undefined ){
|
if (l.properties.altitude !== null && l.properties.altitude !== undefined) {
|
||||||
trkpt += ` <ele>${l.properties.altitude}</ele>`
|
trkpt += ` <ele>${l.properties.altitude}</ele>`
|
||||||
}
|
}
|
||||||
trkpt += " </trkpt>"
|
trkpt += " </trkpt>"
|
||||||
trackPoints.push(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">'
|
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 header + "\n<name>" + title + "</name>\n<trk><trkseg>\n" + trackPoints.join("\n") + "\n</trkseg></trk></gpx>"
|
||||||
}
|
}
|
||||||
|
|
||||||
return new UploadTraceToOsmUI(getTrace, state,{
|
return new UploadTraceToOsmUI(getTrace, state, {
|
||||||
whenUploaded: async () => {
|
whenUploaded: async () => {
|
||||||
state.historicalUserLocations.features.setData([])
|
state.historicalUserLocations.features.setData([])
|
||||||
}
|
}
|
||||||
|
|
|
@ -242,12 +242,15 @@
|
||||||
"uploadGpx": {
|
"uploadGpx": {
|
||||||
"choosePermission": "Choose below if your track should be shared:",
|
"choosePermission": "Choose below if your track should be shared:",
|
||||||
"confirm": "Confirm upload",
|
"confirm": "Confirm upload",
|
||||||
"description": {
|
|
||||||
"intro": "Optionally, you can enter a description of your trace below",
|
|
||||||
"title": "Description"
|
|
||||||
},
|
|
||||||
"intro0": "By uploading your track, OpenStreetMap.org will retain a full copy of the track.",
|
"intro0": "By uploading your track, OpenStreetMap.org will retain a full copy of the track.",
|
||||||
"intro1": "You will be able to download your track again and to load them into OpenStreetMap editing programs",
|
"intro1": "You will be able to download your track again and to load them into OpenStreetMap editing programs",
|
||||||
|
"meta": {
|
||||||
|
"descriptionIntro": "Optionally, you can enter a description of your trace:",
|
||||||
|
"descriptionPlaceHolder": "Enter a description of your trace",
|
||||||
|
"intro": "Add a title for your track:",
|
||||||
|
"title": "Title and description",
|
||||||
|
"titlePlaceholder": "Enter the title of your trace"
|
||||||
|
},
|
||||||
"modes": {
|
"modes": {
|
||||||
"private": {
|
"private": {
|
||||||
"docs": "The points of your track will be shared and aggregated among other tracks. The full track will be visible to you and you will be able to load it into other editing programs. OpenStreetMap.org retains a copy of your trace",
|
"docs": "The points of your track will be shared and aggregated among other tracks. The full track will be visible to you and you will be able to load it into other editing programs. OpenStreetMap.org retains a copy of your trace",
|
||||||
|
@ -258,8 +261,8 @@
|
||||||
"name": "Public"
|
"name": "Public"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"placeHolder": "Enter a description of your trace",
|
|
||||||
"title": "Upload your track to OpenStreetMap.org",
|
"title": "Upload your track to OpenStreetMap.org",
|
||||||
|
"uploadFinished": "Your track has been uploaded!",
|
||||||
"uploading": "Uploading your trace..."
|
"uploading": "Uploading your trace..."
|
||||||
},
|
},
|
||||||
"useSearch": "Use the search above to see presets",
|
"useSearch": "Use the search above to see presets",
|
||||||
|
|
Loading…
Reference in a new issue