From 9c78a2e931a350f791e01d1aac1b0cab4d873323 Mon Sep 17 00:00:00 2001 From: Sebastian Hugentobler Date: Wed, 16 Jun 2021 10:29:25 +0200 Subject: [PATCH] add wapoints to gpx file --- background.js | 39 +++++++++++++++++++++++++++++++++------ 1 file changed, 33 insertions(+), 6 deletions(-) diff --git a/background.js b/background.js index 75da0bd..7d624fd 100644 --- a/background.js +++ b/background.js @@ -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 ``; + 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 ``; +} + +/** + * 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 ` + + ${point.altitude} + ${point.display_name} + `; } /** @@ -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)} Track ${routeTitle}