Add 'upload GPX-trace to OSM' code, small improvements to gps_track-layer
This commit is contained in:
parent
e721146ca1
commit
9cd83af941
5 changed files with 98 additions and 6 deletions
|
@ -340,7 +340,7 @@ export class GeoOperations {
|
||||||
return turf.lineIntersect(feature, otherFeature).features.map(p => <[number, number]>p.geometry.coordinates)
|
return turf.lineIntersect(feature, otherFeature).features.map(p => <[number, number]>p.geometry.coordinates)
|
||||||
}
|
}
|
||||||
|
|
||||||
public static AsGpx(feature, generatedWithLayer?: LayerConfig) {
|
public static AsGpx(feature, generatedWithLayer?: LayerConfig) : string{
|
||||||
|
|
||||||
const metadata = {}
|
const metadata = {}
|
||||||
const tags = feature.properties
|
const tags = feature.properties
|
||||||
|
|
|
@ -9,6 +9,7 @@ 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";
|
||||||
|
|
||||||
export default class UserDetails {
|
export default class UserDetails {
|
||||||
|
|
||||||
|
@ -30,10 +31,13 @@ export default class UserDetails {
|
||||||
export class OsmConnection {
|
export class OsmConnection {
|
||||||
|
|
||||||
public static readonly oauth_configs = {
|
public static readonly oauth_configs = {
|
||||||
|
|
||||||
"osm": {
|
"osm": {
|
||||||
oauth_consumer_key: 'hivV7ec2o49Two8g9h8Is1VIiVOgxQ1iYexCbvem',
|
oauth_consumer_key: 'hivV7ec2o49Two8g9h8Is1VIiVOgxQ1iYexCbvem',
|
||||||
oauth_secret: 'wDBRTCem0vxD7txrg1y6p5r8nvmz8tAhET7zDASI',
|
oauth_secret: 'wDBRTCem0vxD7txrg1y6p5r8nvmz8tAhET7zDASI',
|
||||||
url: "https://www.openstreetmap.org"
|
url: "https://www.openstreetmap.org"
|
||||||
|
// OAUTH 1.0 application
|
||||||
|
// https://www.openstreetmap.org/user/Pieter%20Vander%20Vennet/oauth_clients/7404
|
||||||
},
|
},
|
||||||
"osm-test": {
|
"osm-test": {
|
||||||
oauth_consumer_key: 'Zgr7EoKb93uwPv2EOFkIlf3n9NLwj5wbyfjZMhz2',
|
oauth_consumer_key: 'Zgr7EoKb93uwPv2EOFkIlf3n9NLwj5wbyfjZMhz2',
|
||||||
|
@ -312,7 +316,82 @@ export class OsmConnection {
|
||||||
})
|
})
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async uploadGpxTrack(geojson: any, options: {
|
||||||
|
description: string,
|
||||||
|
visibility: "private" | "public" | "trackable" | "identifiable",
|
||||||
|
filename?: string
|
||||||
|
/**
|
||||||
|
* Some words to give some properties;
|
||||||
|
*
|
||||||
|
* Note: these are called 'tags' on the wiki, but I opted to name them 'labels' instead as they aren't "key=value" tags, but just words.
|
||||||
|
*/
|
||||||
|
labels: string[]
|
||||||
|
}): Promise<{ id: number }> {
|
||||||
|
const gpx = GeoOperations.AsGpx(geojson)
|
||||||
|
if (this._dryRun.data) {
|
||||||
|
console.warn("Dryrun enabled - not actually uploading GPX ", gpx)
|
||||||
|
return new Promise<{ id: number }>((ok, error) => {
|
||||||
|
window.setTimeout(() => ok({id: Math.floor(Math.random() * 1000)}), Math.random() * 5000)
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
const contents = {
|
||||||
|
"file": gpx,
|
||||||
|
"description": options.description,
|
||||||
|
"tags": options.labels.join(","),
|
||||||
|
"visibility": options.visibility
|
||||||
|
}
|
||||||
|
|
||||||
|
const extras = {
|
||||||
|
"file": "; filename=\""+options.filename+"\"\r\nContent-Type: application/gpx+xml"
|
||||||
|
}
|
||||||
|
|
||||||
|
const auth = this.auth;
|
||||||
|
const boundary ="987654"
|
||||||
|
|
||||||
|
var body = ""
|
||||||
|
for (var key in contents) {
|
||||||
|
body += "--" + boundary + "\r\n"
|
||||||
|
body += "Content-Disposition: form-data; name=\"" + key + "\""
|
||||||
|
if(extras[key] !== undefined){
|
||||||
|
body += extras[key]
|
||||||
|
}
|
||||||
|
body += "\r\n\r\n"
|
||||||
|
body += contents[key] + "\r\n"
|
||||||
|
}
|
||||||
|
body += "--" + boundary + "--\r\n"
|
||||||
|
|
||||||
|
|
||||||
|
return new Promise((ok, error) => {
|
||||||
|
auth.xhr({
|
||||||
|
method: 'POST',
|
||||||
|
path: `/api/0.6/gpx/create`,
|
||||||
|
options: {
|
||||||
|
header:
|
||||||
|
{
|
||||||
|
"Content-Type": "multipart/form-data; boundary=" + boundary,
|
||||||
|
"Content-Length": body.length
|
||||||
|
}
|
||||||
|
},
|
||||||
|
content: body
|
||||||
|
|
||||||
|
}, function (
|
||||||
|
err,
|
||||||
|
response: string) {
|
||||||
|
console.log("RESPONSE IS", response)
|
||||||
|
if (err !== null) {
|
||||||
|
error(err)
|
||||||
|
} else {
|
||||||
|
const parsed = JSON.parse(response)
|
||||||
|
console.log("Uploaded GPX track", parsed)
|
||||||
|
ok({id: parsed})
|
||||||
|
}
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
public addCommentToNode(id: number | string, text: string): Promise<any> {
|
public addCommentToNode(id: number | string, text: string): Promise<any> {
|
||||||
if (this._dryRun.data) {
|
if (this._dryRun.data) {
|
||||||
console.warn("Dryrun enabled - not actually adding comment ", text, "to note ", id)
|
console.warn("Dryrun enabled - not actually adding comment ", text, "to note ", id)
|
||||||
|
|
|
@ -28,7 +28,6 @@ export class LoginToggle extends VariableUiElement {
|
||||||
const login = new LoginButton(text, state)
|
const login = new LoginButton(text, state)
|
||||||
super(
|
super(
|
||||||
state.osmConnection.loadingStatus.map(osmConnectionState => {
|
state.osmConnection.loadingStatus.map(osmConnectionState => {
|
||||||
console.trace("Current osm state is ", osmConnectionState)
|
|
||||||
if(osmConnectionState === "loading"){
|
if(osmConnectionState === "loading"){
|
||||||
return loading
|
return loading
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,11 +1,22 @@
|
||||||
{
|
{
|
||||||
"id": "gps_location_history",
|
"id": "gps_location_history",
|
||||||
"description": "Meta layer which contains the previous locations of the user as single points. This is mainly for technical reasons, e.g. to keep match the distance to the modified object",
|
"description": "Meta layer which contains the previous locations of the user as single points. This is mainly for technical reasons, e.g. to keep match the distance to the modified object",
|
||||||
"minzoom": 0,
|
"minzoom": 1,
|
||||||
|
"name": {
|
||||||
|
"en": "Location history as points",
|
||||||
|
"nl": "Locatiegeschiedenis als punten"
|
||||||
|
},
|
||||||
"source": {
|
"source": {
|
||||||
"osmTags": "user:location=yes",
|
"osmTags": "user:location=yes",
|
||||||
"#": "Cache is disabled here as these points are kept seperately",
|
"#": "Cache is disabled here as these points are kept seperately",
|
||||||
"maxCacheAge": 0
|
"maxCacheAge": 0
|
||||||
},
|
},
|
||||||
"mapRendering": null
|
"shownByDefault": false,
|
||||||
|
"mapRendering":[
|
||||||
|
{
|
||||||
|
"location": ["point","centroid"],
|
||||||
|
"icon": "square:red",
|
||||||
|
"iconSize": "5,5,center"
|
||||||
|
}
|
||||||
|
]
|
||||||
}
|
}
|
|
@ -9,6 +9,9 @@
|
||||||
"export_as_gpx": {
|
"export_as_gpx": {
|
||||||
"render": "{export_as_gpx()}"
|
"render": "{export_as_gpx()}"
|
||||||
},
|
},
|
||||||
|
"export_as_geojson": {
|
||||||
|
"render": "{export_as_geojson()}"
|
||||||
|
},
|
||||||
"wikipedia": {
|
"wikipedia": {
|
||||||
"render": "{wikipedia():max-height:25rem}",
|
"render": "{wikipedia():max-height:25rem}",
|
||||||
"question": {
|
"question": {
|
||||||
|
@ -828,4 +831,4 @@
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue