add wapoints to gpx file
This commit is contained in:
parent
3c9e6a2865
commit
9c78a2e931
@ -13,9 +13,9 @@ let gpxTrack = null;
|
|||||||
* (https://www.swisstopo.admin.ch/en/knowledge-facts/surveying-geodesy/reference-systems/map-projections.html).
|
* (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.
|
* @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
|
// convert LV95 into the civilian system
|
||||||
let y_aux = (point[0] - 2600000)/1000000;
|
let y_aux = (point[0] - 2600000)/1000000;
|
||||||
let x_aux = (point[1] - 1200000)/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.0447 * Math.pow(y_aux, 2) * x_aux -
|
||||||
0.0140 * Math.pow(x_aux, 3);
|
0.0140 * Math.pow(x_aux, 3);
|
||||||
|
|
||||||
let lng = 2.6779094 +
|
let lon = 2.6779094 +
|
||||||
4.728982 * y_aux +
|
4.728982 * y_aux +
|
||||||
0.791484 * y_aux * x_aux +
|
0.791484 * y_aux * x_aux +
|
||||||
0.1306 * y_aux * Math.pow(x_aux, 2) -
|
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)
|
// unit 10000" to 1" and seconds to degrees (dec)
|
||||||
lat = lat * 100 / 36;
|
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"
|
xsi:schemaLocation="http://www.topografix.com/GPX/1/0 http://www.topografix.com/GPX/1/0/gpx.xsd"
|
||||||
version="1.0"
|
version="1.0"
|
||||||
creator="SAC-Tourenportal GPX Downloader">
|
creator="SAC-Tourenportal GPX Downloader">
|
||||||
|
${toWayPoint(geoJson.departure_point)}
|
||||||
|
${toWayPoint(geoJson.destination_poi)}
|
||||||
<trk>
|
<trk>
|
||||||
<name>Track ${routeTitle}</name>
|
<name>Track ${routeTitle}</name>
|
||||||
<trkseg>
|
<trkseg>
|
||||||
|
Loading…
Reference in New Issue
Block a user