forked from MapComplete/MapComplete
Add possibility to upload your travelled track to OSM
This commit is contained in:
parent
9424364f3f
commit
312db3ad50
11 changed files with 208 additions and 44 deletions
|
@ -1,9 +1,9 @@
|
|||
import * as turf from '@turf/turf'
|
||||
import {AllGeoJSON, booleanWithin, Coord, Feature, Geometry, MultiPolygon, Polygon} from '@turf/turf'
|
||||
import {BBox} from "./BBox";
|
||||
import togpx from "togpx"
|
||||
import Constants from "../Models/Constants";
|
||||
import LayerConfig from "../Models/ThemeConfig/LayerConfig";
|
||||
import {AllGeoJSON, booleanWithin, Coord, Feature, Geometry, MultiPolygon, Polygon, Properties} from "@turf/turf";
|
||||
|
||||
export class GeoOperations {
|
||||
|
||||
|
@ -383,22 +383,21 @@ export class GeoOperations {
|
|||
return turf.lineIntersect(feature, otherFeature).features.map(p => <[number, number]>p.geometry.coordinates)
|
||||
}
|
||||
|
||||
public static AsGpx(feature, generatedWithLayer?: LayerConfig) : string{
|
||||
public static AsGpx(feature: Feature, options?: {layer?: LayerConfig, gpxMetadata?: any }) : string{
|
||||
|
||||
const metadata = {}
|
||||
const metadata = options?.gpxMetadata ?? {}
|
||||
metadata["time"] = metadata["time"] ?? new Date().toISOString()
|
||||
const tags = feature.properties
|
||||
|
||||
if (generatedWithLayer !== undefined) {
|
||||
if (options?.layer !== undefined) {
|
||||
|
||||
metadata["name"] = generatedWithLayer.title?.GetRenderValue(tags)?.Subs(tags)?.txt
|
||||
metadata["desc"] = "Generated with MapComplete layer " + generatedWithLayer.id
|
||||
metadata["name"] = options?.layer.title?.GetRenderValue(tags)?.Subs(tags)?.txt
|
||||
metadata["desc"] = "Generated with MapComplete layer " + options?.layer.id
|
||||
if (tags._backend?.contains("openstreetmap")) {
|
||||
metadata["copyright"] = "Data copyrighted by OpenStreetMap-contributors, freely available under ODbL. See https://www.openstreetmap.org/copyright"
|
||||
metadata["author"] = tags["_last_edit:contributor"]
|
||||
metadata["link"] = "https://www.openstreetmap.org/" + tags.id
|
||||
metadata["time"] = tags["_last_edit:timestamp"]
|
||||
} else {
|
||||
metadata["time"] = new Date().toISOString()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -9,6 +9,7 @@ import {Utils} from "../../Utils";
|
|||
import {OsmObject} from "./OsmObject";
|
||||
import {Changes} from "./Changes";
|
||||
import {GeoOperations} from "../GeoOperations";
|
||||
import { Feature } from "@turf/turf";
|
||||
|
||||
export default class UserDetails {
|
||||
|
||||
|
@ -322,7 +323,7 @@ export class OsmConnection {
|
|||
|
||||
}
|
||||
|
||||
public async uploadGpxTrack(geojson: any, options: {
|
||||
public async uploadGpxTrack(gpx: string, options: {
|
||||
description: string,
|
||||
visibility: "private" | "public" | "trackable" | "identifiable",
|
||||
filename?: string
|
||||
|
@ -333,7 +334,6 @@ export class OsmConnection {
|
|||
*/
|
||||
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) => {
|
||||
|
@ -355,8 +355,8 @@ export class OsmConnection {
|
|||
const auth = this.auth;
|
||||
const boundary ="987654"
|
||||
|
||||
var body = ""
|
||||
for (var key in contents) {
|
||||
let body = ""
|
||||
for (const key in contents) {
|
||||
body += "--" + boundary + "\r\n"
|
||||
body += "Content-Disposition: form-data; name=\"" + key + "\""
|
||||
if(extras[key] !== undefined){
|
||||
|
|
|
@ -69,7 +69,7 @@ export default class MapState extends UserRelatedState {
|
|||
public currentUserLocation: SimpleFeatureSource;
|
||||
|
||||
/**
|
||||
* All previously visited points
|
||||
* All previously visited points, with their metadata
|
||||
*/
|
||||
public historicalUserLocations: SimpleFeatureSource;
|
||||
/**
|
||||
|
@ -77,6 +77,11 @@ export default class MapState extends UserRelatedState {
|
|||
* Time in seconds
|
||||
*/
|
||||
public gpsLocationHistoryRetentionTime = new UIEventSource(7 * 24 * 60 * 60, "gps_location_retention")
|
||||
/**
|
||||
* A featureSource containing a single linestring which has the GPS-history of the user.
|
||||
* However, metadata (such as when every single point was visited) is lost here (but is kept in `historicalUserLocations`.
|
||||
* Note that this featureSource is _derived_ from 'historicalUserLocations'
|
||||
*/
|
||||
public historicalUserLocationsTrack: FeatureSourceForLayer & Tiled;
|
||||
|
||||
/**
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue