Skip to content

Ascent and descent metadata in elevation chart #29

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Dec 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
137 changes: 79 additions & 58 deletions assets/dist/waymark-js/js/waymark-js.js
Original file line number Diff line number Diff line change
Expand Up @@ -1962,7 +1962,9 @@ Copyright (c) 2016 Dominik Moritz */
this.track_info = L.extend({}, this.track_info, {
distance: this._distance,
elevation_max: this._maxElevation,
elevation_min: this._minElevation
elevation_min: this._minElevation,
ascent : this._ascent,
descent : this._descent
});

this._layers = this._layers || {};
Expand Down Expand Up @@ -2428,6 +2430,19 @@ Copyright (c) 2016 Dominik Moritz */
if (!isNaN(z)) {
eleMax = eleMax < z ? z : eleMax;
eleMin = eleMin > z ? z : eleMin;

// calculate new ascent or descent
let dz = z - this._lastValidZ ;
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;
}

// set up last valid z value
this._lastValidZ = z;
}

Expand Down Expand Up @@ -3549,9 +3564,11 @@ Copyright (c) 2016 Dominik Moritz */
this.track_info.distance = this._distance || 0;
this.track_info.elevation_max = this._maxElevation || 0;
this.track_info.elevation_min = this._minElevation || 0;
this.track_info.ascent = this._ascent || 0;
this.track_info.descent = this._descent || 0;

if (this.options.summary) {
this.summaryDiv.innerHTML += '<span class="totlen"><span class="summarylabel">' + L._("Total Length: ") + '</span><span class="summaryvalue">' + this.track_info.distance.toFixed(2) + ' ' + this._xLabel + '</span></span><span class="maxele"><span class="summarylabel">' + L._("Max Elevation: ") + '</span><span class="summaryvalue">' + this.track_info.elevation_max.toFixed(2) + ' ' + this._yLabel + '</span></span><span class="minele"><span class="summarylabel">' + L._("Min Elevation: ") + '</span><span class="summaryvalue">' + this.track_info.elevation_min.toFixed(2) + ' ' + this._yLabel + '</span></span>';
this.summaryDiv.innerHTML += '<span class="totlen"><span class="summarylabel">' + L._("Total Length: ") + '</span><span class="summaryvalue">' + this.track_info.distance.toFixed(2) + ' ' + this._xLabel + '</span></span><span class="maxele"><span class="summarylabel">' + L._("Max Elevation: ") + '</span><span class="summaryvalue">' + this.track_info.elevation_max.toFixed(2) + ' ' + this._yLabel + '</span></span><span class="minele"><span class="summarylabel">' + L._("Min Elevation: ") + '</span><span class="summaryvalue">' + this.track_info.elevation_min.toFixed(2) + ' ' + this._yLabel + '</span></span><span class="totasc"><span class="summarylabel">' + L._("Total Ascent: ") + '</span><span class="summaryvalue">' + this.track_info.ascent.toFixed(0) + ' ' + this._yLabel + '</span></span><span class="totdesc"><span class="summarylabel">' + L._("Total Descent: ") + '</span><span class="summaryvalue">' + this.track_info.descent.toFixed(0) + ' ' + this._yLabel + '</span></span>';
}
if (this.options.downloadLink && this._downloadURL) { // TODO: generate dynamically file content instead of using static file urls.
this.summaryDiv.innerHTML += '<span class="download"><a href="#">' + L._('Download') + '</a></span>';
Expand Down Expand Up @@ -5848,62 +5865,62 @@ function interpolateBetweenPoints(ptA, ptB, ratio) {
};
}

(function() {
// save these original methods before they are overwritten
var proto_initIcon = Waymark_L.Marker.prototype._initIcon;
var proto_setPos = Waymark_L.Marker.prototype._setPos;
var oldIE = (Waymark_L.DomUtil.TRANSFORM === 'msTransform');
Waymark_L.Marker.addInitHook(function () {
var iconOptions = this.options.icon && this.options.icon.options;
var iconAnchor = iconOptions && this.options.icon.options.iconAnchor;
if (iconAnchor) {
iconAnchor = (iconAnchor[0] + 'px ' + iconAnchor[1] + 'px');
}
this.options.rotationOrigin = this.options.rotationOrigin || iconAnchor || 'center bottom' ;
this.options.rotationAngle = this.options.rotationAngle || 0;
// Ensure marker keeps rotated during dragging
this.on('drag', function(e) { e.target._applyRotation(); });
});
Waymark_L.Marker.include({
_initIcon: function() {
proto_initIcon.call(this);
},
_setPos: function (pos) {
proto_setPos.call(this, pos);
this._applyRotation();
},
_applyRotation: function () {
if(this.options.rotationAngle) {
this._icon.style[Waymark_L.DomUtil.TRANSFORM+'Origin'] = this.options.rotationOrigin;
if(oldIE) {
// for IE 9, use the 2D rotation
this._icon.style[Waymark_L.DomUtil.TRANSFORM] = 'rotate(' + this.options.rotationAngle + 'deg)';
} else {
// for modern browsers, prefer the 3D accelerated version
this._icon.style[Waymark_L.DomUtil.TRANSFORM] += ' rotateZ(' + this.options.rotationAngle + 'deg)';
}
}
},
setRotationAngle: function(angle) {
this.options.rotationAngle = angle;
this.update();
return this;
},
setRotationOrigin: function(origin) {
this.options.rotationOrigin = origin;
this.update();
return this;
}
});
(function() {
// save these original methods before they are overwritten
var proto_initIcon = Waymark_L.Marker.prototype._initIcon;
var proto_setPos = Waymark_L.Marker.prototype._setPos;

var oldIE = (Waymark_L.DomUtil.TRANSFORM === 'msTransform');

Waymark_L.Marker.addInitHook(function () {
var iconOptions = this.options.icon && this.options.icon.options;
var iconAnchor = iconOptions && this.options.icon.options.iconAnchor;
if (iconAnchor) {
iconAnchor = (iconAnchor[0] + 'px ' + iconAnchor[1] + 'px');
}
this.options.rotationOrigin = this.options.rotationOrigin || iconAnchor || 'center bottom' ;
this.options.rotationAngle = this.options.rotationAngle || 0;

// Ensure marker keeps rotated during dragging
this.on('drag', function(e) { e.target._applyRotation(); });
});

Waymark_L.Marker.include({
_initIcon: function() {
proto_initIcon.call(this);
},

_setPos: function (pos) {
proto_setPos.call(this, pos);
this._applyRotation();
},

_applyRotation: function () {
if(this.options.rotationAngle) {
this._icon.style[Waymark_L.DomUtil.TRANSFORM+'Origin'] = this.options.rotationOrigin;

if(oldIE) {
// for IE 9, use the 2D rotation
this._icon.style[Waymark_L.DomUtil.TRANSFORM] = 'rotate(' + this.options.rotationAngle + 'deg)';
} else {
// for modern browsers, prefer the 3D accelerated version
this._icon.style[Waymark_L.DomUtil.TRANSFORM] += ' rotateZ(' + this.options.rotationAngle + 'deg)';
}
}
},

setRotationAngle: function(angle) {
this.options.rotationAngle = angle;
this.update();
return this;
},

setRotationOrigin: function(origin) {
this.options.rotationOrigin = origin;
this.update();
return this;
}
});
})();

L$1.Symbol = L$1.Symbol || {};
Expand Down Expand Up @@ -7387,6 +7404,8 @@ var waymark_js_localize = {
label_total_length: "Total Length: ",
label_max_elevation: "Max. Elevation: ",
label_min_elevation: "Min. Elevation: ",
label_ascent: "Total Ascent: ",
label_descent: "Total Descent: ",
//Editor
add_line_title: "Draw a Line",
add_photo_title: "Upload an Image",
Expand Down Expand Up @@ -9213,6 +9232,8 @@ function Waymark_Map_Viewer() {
"Total Length: ": waymark_js.lang.label_total_length,
"Max Elevation: ": waymark_js.lang.label_max_elevation,
"Min Elevation: ": waymark_js.lang.label_min_elevation,
"Total Ascent: ": waymark_js.lang.label_ascent,
"Total Descent: ": waymark_js.lang.label_descent,
});
Waymark_L.setLocale("waymark");

Expand Down
29 changes: 16 additions & 13 deletions assets/dist/waymark-js/js/waymark-js.min.js

Large diffs are not rendered by default.

21 changes: 19 additions & 2 deletions waymark-js/libs/js/leaflet-elevation.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions waymark-js/src/js/Waymark_Map.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ var waymark_js_localize = {
label_total_length: "Total Length: ",
label_max_elevation: "Max. Elevation: ",
label_min_elevation: "Min. Elevation: ",
label_ascent: "Total Ascent: ",
label_descent: "Total Descent: ",
//Editor
add_line_title: "Draw a Line",
add_photo_title: "Upload an Image",
Expand Down
2 changes: 2 additions & 0 deletions waymark-js/src/js/Waymark_Map_Viewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,8 @@ function Waymark_Map_Viewer() {
"Total Length: ": waymark_js.lang.label_total_length,
"Max Elevation: ": waymark_js.lang.label_max_elevation,
"Min Elevation: ": waymark_js.lang.label_min_elevation,
"Total Ascent: ": waymark_js.lang.label_ascent,
"Total Descent: ": waymark_js.lang.label_descent,
});
Waymark_L.setLocale("waymark");

Expand Down