add wapoints to gpx file
This commit is contained in:
parent
3c9e6a2865
commit
9c78a2e931
@ -1,7 +1,7 @@
|
||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
||||
|
||||
|
||||
let gpxTrack = null;
|
||||
|
||||
/**
|
||||
@ -13,9 +13,9 @@ let gpxTrack = null;
|
||||
* (https://www.swisstopo.admin.ch/en/knowledge-facts/surveying-geodesy/reference-systems/map-projections.html).
|
||||
*
|
||||
* @param {*} point Array of Swiss projection coordinates, position 0 is E and 1 is N.
|
||||
* @returns Track point xml node for gpx.
|
||||
* @returns Calculated lat and lon.
|
||||
*/
|
||||
function toTrackPoint(point) {
|
||||
function toWGS84(point) {
|
||||
// convert LV95 into the civilian system
|
||||
let y_aux = (point[0] - 2600000)/1000000;
|
||||
let x_aux = (point[1] - 1200000)/1000000;
|
||||
@ -28,7 +28,7 @@ function toTrackPoint(point) {
|
||||
0.0447 * Math.pow(y_aux, 2) * x_aux -
|
||||
0.0140 * Math.pow(x_aux, 3);
|
||||
|
||||
let lng = 2.6779094 +
|
||||
let lon = 2.6779094 +
|
||||
4.728982 * y_aux +
|
||||
0.791484 * y_aux * x_aux +
|
||||
0.1306 * y_aux * Math.pow(x_aux, 2) -
|
||||
@ -36,9 +36,34 @@ function toTrackPoint(point) {
|
||||
|
||||
// unit 10000" to 1" and seconds to degrees (dec)
|
||||
lat = lat * 100 / 36;
|
||||
lng = lng * 100 / 36;
|
||||
lon = lon * 100 / 36;
|
||||
|
||||
return `<trkpt lat="${lat}" lon="${lng}"/>`;
|
||||
return {lat: lat, lon: lon};
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the gpx trackpoint representation of a Swiss projection coordinate point.
|
||||
*
|
||||
* @param {*} point Array of Swiss projection coordinates, position 0 is E and 1 is N.
|
||||
* @returns Track point xml node for gpx.
|
||||
*/
|
||||
function toTrackPoint(point) {
|
||||
let wgs84Point = toWGS84(point);
|
||||
return `<trkpt lat="${wgs84Point.lat}" lon="${wgs84Point.lon}"/>`;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the gpx waypoint representation of a route portal point.
|
||||
*
|
||||
* @returns Way point xml node for gpx.
|
||||
*/
|
||||
function toWayPoint(point) {
|
||||
let wgs84Point = toWGS84(point.geom.coordinates);
|
||||
return `
|
||||
<wpt lat="${wgs84Point.lat}" lon="${wgs84Point.lon}">
|
||||
<ele>${point.altitude}</ele>
|
||||
<name>${point.display_name}</name>
|
||||
</wpt>`;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -69,6 +94,8 @@ function toGpx(geoJson) {
|
||||
xsi:schemaLocation="http://www.topografix.com/GPX/1/0 http://www.topografix.com/GPX/1/0/gpx.xsd"
|
||||
version="1.0"
|
||||
creator="SAC-Tourenportal GPX Downloader">
|
||||
${toWayPoint(geoJson.departure_point)}
|
||||
${toWayPoint(geoJson.destination_poi)}
|
||||
<trk>
|
||||
<name>Track ${routeTitle}</name>
|
||||
<trkseg>
|
||||
|
Loading…
Reference in New Issue
Block a user