Ascent and descent values are too high, because they are calculated every 1 to 4 meters. They should be calculated in bigger walking distances. My suggestion is 10 meters.
I have adjusted the source code, which is pasted at the end of this message. Only what I have marked with DGF are changes made by me, the rest is the original. There are two functions in leaflet-elevation.js that are affected: _addData and _addPoint.
Best regards.
Daniel.
if (geom) {
switch (geom.type) {
case 'LineString':
this._addGeoJSONData(geom.coordinates);
break;
case 'MultiLineString':
geom.coordinates.forEach(coords => this._addGeoJSONData(coords));
break;
default:
console.warn('Unsopperted GeoJSON feature geometry type:' + geom.type);
}
//DGF if elevation difference is too small, make ascent and descent equal
if (Math.abs(this._ascent-this._descent) <= 10)
{
this.track_info.descent = this.track_info.ascent;
this._descent = this.track_info.descent;
}
//DGF end
}
if (feat) {
d.features.forEach(feature => this._addData(feature));
}
if (gpx) {
this._addGPXdata(d._latlngs);
}
},
let data = this._data || [];
let eleMax = this._maxElevation || -Infinity;
let eleMin = this._minElevation || +Infinity;
let dist = this._distance || 0;
//DGF
let elevDist = this._elevationMesurementDistance || 0;
//DGF end
let curr = new L.LatLng(x, y);
let prev = data.length ? data[data.length - 1].latlng : curr;
let delta = curr.distanceTo(prev) * this._distanceFactor;
dist = dist + Math.round(delta / 1000 * 100000) / 100000;
//DGF
elevDist = elevDist + delta;
//DGF end
// check and fix missing elevation data on last added point
if (!this.options.skipNullZCoords && data.length > 0)
{
let prevZ = data[data.length - 1].z;
if (isNaN(prevZ)) {
let lastZ = this._lastValidZ;
let currZ = z * this._heightFactor;
if (!isNaN(lastZ) && !isNaN(currZ)) {
prevZ = (lastZ + currZ) / 2;
} else if (!isNaN(lastZ)) {
prevZ = lastZ;
} else if (!isNaN(currZ)) {
prevZ = currZ;
}
if (!isNaN(prevZ)) data[data.length - 1].z = prevZ;
else data.splice(data.length - 1, 1);
}
}
z = z * this._heightFactor;
// skip point if it has not elevation
if (!isNaN(z))
{
eleMax = eleMax < z ? z : eleMax;
eleMin = eleMin > z ? z : eleMin;
// calculate new ascent or descent
//DGF measure elevation only every 10 meters of walking distance
if (elevDist >= 10 || isNaN(this._lastMeasuredZ))
{
elevDist = 0;
let dz = z - this._lastMeasuredZ ; //DGF
if (dz > 0)
{
this.track_info.ascent = (this.track_info.ascent || 0) + dz; // Total Ascent
this._ascent = this.track_info.ascent;
}
else if (dz < 0)
{
this.track_info.descent = (this.track_info.descent || 0) - dz; // Total Descent
this._descent = this.track_info.descent;
}
this._lastMeasuredZ = z; //DGF
}
this._elevationMesurementDistance = elevDist;
//DGF end
this._lastValidZ = z;
// set up last valid z value
}
data.push({
dist: dist,
x: x,
y: y,
z: z,
latlng: curr
});
this._data = data;
this._distance = dist;
this._maxElevation = eleMax;
this._minElevation = eleMin;
},