add distance & elevation on tracks

This commit is contained in:
2019-05-11 01:12:24 +02:00
parent 94ae30e1f3
commit 667a094f54
7 changed files with 21942 additions and 17667 deletions

34
script/leaflet.min.js vendored
View File

@@ -578,13 +578,22 @@ L.Control.Elevation = L.Control.extend({
var data = this._data || [];
var dist = this._dist || 0;
var ele = this._maxElevation || 0;
var eleDrop = this._elevationDrop || 0;
var eleGain = this._elevationGain || 0;
for (var i = 0; i < coords.length; i++) {
var s = new L.LatLng(coords[i][1], coords[i][0]);
var e = new L.LatLng(coords[i ? i - 1 : 0][1], coords[i ? i - 1 : 0][0]);
var newdist = opts.imperial ? s.distanceTo(e) * this.__mileFactor : s.distanceTo(e);
dist = dist + Math.round(newdist / 1000 * 100000) / 100000;
ele = ele < coords[i][2] ? coords[i][2] : ele;
data.push({
if(i > 0) {
var eleDelta = coords[i][2] - coords[i - 1][2];
eleDrop += Math.min(eleDelta, 0);
eleGain += Math.max(eleDelta, 0);
}
data.push({
dist: dist,
altitude: opts.imperial ? coords[i][2] * this.__footFactor : coords[i][2],
x: coords[i][0],
@@ -596,6 +605,8 @@ L.Control.Elevation = L.Control.extend({
this._data = data;
ele = opts.imperial ? ele * this.__footFactor : ele;
this._maxElevation = ele;
this._elevationDrop = eleDrop;
this._elevationGain = eleGain;
}
},
@@ -608,12 +619,19 @@ L.Control.Elevation = L.Control.extend({
var data = this._data || [];
var dist = this._dist || 0;
var ele = this._maxElevation || 0;
var eleDrop = this._elevationDrop || 0;
var eleGain = this._elevationGain || 0;
for (var i = 0; i < coords.length; i++) {
var s = coords[i];
var e = coords[i ? i - 1 : 0];
var newdist = opts.imperial ? s.distanceTo(e) * this.__mileFactor : s.distanceTo(e);
dist = dist + Math.round(newdist / 1000 * 100000) / 100000;
ele = ele < s.meta.ele ? s.meta.ele : ele;
var eleDelta = s.meta.ele - e.meta.ele;
eleDrop += Math.min(eleDelta, 0);
eleGain += Math.max(eleDelta, 0);
data.push({
dist: dist,
altitude: opts.imperial ? s.meta.ele * this.__footFactor : s.meta.ele,
@@ -626,6 +644,8 @@ L.Control.Elevation = L.Control.extend({
this._data = data;
ele = opts.imperial ? ele * this.__footFactor : ele;
this._maxElevation = ele;
this._elevationDrop = eleDrop;
this._elevationGain = eleGain;
}
},
@@ -766,14 +786,16 @@ L.Control.Elevation = L.Control.extend({
this._updateAxis();
this._fullExtent = this._calculateFullExtent(this._data);
},
},
/*
* Reset data
*/
_clearData: function() {
this._data = null;
this._dist = null;
this._elevationDrop = null;
this._elevationGain = null;
this._maxElevation = null;
},
@@ -802,8 +824,10 @@ L.Control.Elevation = L.Control.extend({
},
show: function() {
this._container.style.display = "block";
}
},
getMetaData: function() {
return {'distance': this._dist, 'elevation_drop': this._elevationDrop, 'elevation_gain': this._elevationGain, 'elevation_max': this._maxElevation};
}
});
L.control.elevation = function(options) {