Skip to content

Commit 0ac0ef3

Browse files
committed
[ascent/descent] add fonctionnalities in dist waymark.js file
1 parent bbccd2c commit 0ac0ef3

File tree

1 file changed

+79
-58
lines changed

1 file changed

+79
-58
lines changed

assets/dist/waymark-js/js/waymark-js.js

Lines changed: 79 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1962,7 +1962,9 @@ Copyright (c) 2016 Dominik Moritz */
19621962
this.track_info = L.extend({}, this.track_info, {
19631963
distance: this._distance,
19641964
elevation_max: this._maxElevation,
1965-
elevation_min: this._minElevation
1965+
elevation_min: this._minElevation,
1966+
ascent : this._ascent,
1967+
descent : this._descent
19661968
});
19671969

19681970
this._layers = this._layers || {};
@@ -2428,6 +2430,19 @@ Copyright (c) 2016 Dominik Moritz */
24282430
if (!isNaN(z)) {
24292431
eleMax = eleMax < z ? z : eleMax;
24302432
eleMin = eleMin > z ? z : eleMin;
2433+
2434+
// calculate new ascent or descent
2435+
let dz = z - this._lastValidZ ;
2436+
if (dz > 0){
2437+
this.track_info.ascent = (this.track_info.ascent || 0) + dz; // Total Ascent
2438+
this._ascent = this.track_info.ascent;
2439+
}
2440+
else if (dz < 0){
2441+
this.track_info.descent = (this.track_info.descent || 0) - dz; // Total Descent
2442+
this._descent = this.track_info.descent;
2443+
}
2444+
2445+
// set up last valid z value
24312446
this._lastValidZ = z;
24322447
}
24332448

@@ -3549,9 +3564,11 @@ Copyright (c) 2016 Dominik Moritz */
35493564
this.track_info.distance = this._distance || 0;
35503565
this.track_info.elevation_max = this._maxElevation || 0;
35513566
this.track_info.elevation_min = this._minElevation || 0;
3567+
this.track_info.ascent = this._ascent || 0;
3568+
this.track_info.descent = this._descent || 0;
35523569

35533570
if (this.options.summary) {
3554-
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>';
3571+
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>';
35553572
}
35563573
if (this.options.downloadLink && this._downloadURL) { // TODO: generate dynamically file content instead of using static file urls.
35573574
this.summaryDiv.innerHTML += '<span class="download"><a href="#">' + L._('Download') + '</a></span>';
@@ -5848,62 +5865,62 @@ function interpolateBetweenPoints(ptA, ptB, ratio) {
58485865
};
58495866
}
58505867

5851-
(function() {
5852-
// save these original methods before they are overwritten
5853-
var proto_initIcon = Waymark_L.Marker.prototype._initIcon;
5854-
var proto_setPos = Waymark_L.Marker.prototype._setPos;
5855-
5856-
var oldIE = (Waymark_L.DomUtil.TRANSFORM === 'msTransform');
5857-
5858-
Waymark_L.Marker.addInitHook(function () {
5859-
var iconOptions = this.options.icon && this.options.icon.options;
5860-
var iconAnchor = iconOptions && this.options.icon.options.iconAnchor;
5861-
if (iconAnchor) {
5862-
iconAnchor = (iconAnchor[0] + 'px ' + iconAnchor[1] + 'px');
5863-
}
5864-
this.options.rotationOrigin = this.options.rotationOrigin || iconAnchor || 'center bottom' ;
5865-
this.options.rotationAngle = this.options.rotationAngle || 0;
5866-
5867-
// Ensure marker keeps rotated during dragging
5868-
this.on('drag', function(e) { e.target._applyRotation(); });
5869-
});
5870-
5871-
Waymark_L.Marker.include({
5872-
_initIcon: function() {
5873-
proto_initIcon.call(this);
5874-
},
5875-
5876-
_setPos: function (pos) {
5877-
proto_setPos.call(this, pos);
5878-
this._applyRotation();
5879-
},
5880-
5881-
_applyRotation: function () {
5882-
if(this.options.rotationAngle) {
5883-
this._icon.style[Waymark_L.DomUtil.TRANSFORM+'Origin'] = this.options.rotationOrigin;
5884-
5885-
if(oldIE) {
5886-
// for IE 9, use the 2D rotation
5887-
this._icon.style[Waymark_L.DomUtil.TRANSFORM] = 'rotate(' + this.options.rotationAngle + 'deg)';
5888-
} else {
5889-
// for modern browsers, prefer the 3D accelerated version
5890-
this._icon.style[Waymark_L.DomUtil.TRANSFORM] += ' rotateZ(' + this.options.rotationAngle + 'deg)';
5891-
}
5892-
}
5893-
},
5894-
5895-
setRotationAngle: function(angle) {
5896-
this.options.rotationAngle = angle;
5897-
this.update();
5898-
return this;
5899-
},
5900-
5901-
setRotationOrigin: function(origin) {
5902-
this.options.rotationOrigin = origin;
5903-
this.update();
5904-
return this;
5905-
}
5906-
});
5868+
(function() {
5869+
// save these original methods before they are overwritten
5870+
var proto_initIcon = Waymark_L.Marker.prototype._initIcon;
5871+
var proto_setPos = Waymark_L.Marker.prototype._setPos;
5872+
5873+
var oldIE = (Waymark_L.DomUtil.TRANSFORM === 'msTransform');
5874+
5875+
Waymark_L.Marker.addInitHook(function () {
5876+
var iconOptions = this.options.icon && this.options.icon.options;
5877+
var iconAnchor = iconOptions && this.options.icon.options.iconAnchor;
5878+
if (iconAnchor) {
5879+
iconAnchor = (iconAnchor[0] + 'px ' + iconAnchor[1] + 'px');
5880+
}
5881+
this.options.rotationOrigin = this.options.rotationOrigin || iconAnchor || 'center bottom' ;
5882+
this.options.rotationAngle = this.options.rotationAngle || 0;
5883+
5884+
// Ensure marker keeps rotated during dragging
5885+
this.on('drag', function(e) { e.target._applyRotation(); });
5886+
});
5887+
5888+
Waymark_L.Marker.include({
5889+
_initIcon: function() {
5890+
proto_initIcon.call(this);
5891+
},
5892+
5893+
_setPos: function (pos) {
5894+
proto_setPos.call(this, pos);
5895+
this._applyRotation();
5896+
},
5897+
5898+
_applyRotation: function () {
5899+
if(this.options.rotationAngle) {
5900+
this._icon.style[Waymark_L.DomUtil.TRANSFORM+'Origin'] = this.options.rotationOrigin;
5901+
5902+
if(oldIE) {
5903+
// for IE 9, use the 2D rotation
5904+
this._icon.style[Waymark_L.DomUtil.TRANSFORM] = 'rotate(' + this.options.rotationAngle + 'deg)';
5905+
} else {
5906+
// for modern browsers, prefer the 3D accelerated version
5907+
this._icon.style[Waymark_L.DomUtil.TRANSFORM] += ' rotateZ(' + this.options.rotationAngle + 'deg)';
5908+
}
5909+
}
5910+
},
5911+
5912+
setRotationAngle: function(angle) {
5913+
this.options.rotationAngle = angle;
5914+
this.update();
5915+
return this;
5916+
},
5917+
5918+
setRotationOrigin: function(origin) {
5919+
this.options.rotationOrigin = origin;
5920+
this.update();
5921+
return this;
5922+
}
5923+
});
59075924
})();
59085925

59095926
L$1.Symbol = L$1.Symbol || {};
@@ -7387,6 +7404,8 @@ var waymark_js_localize = {
73877404
label_total_length: "Total Length: ",
73887405
label_max_elevation: "Max. Elevation: ",
73897406
label_min_elevation: "Min. Elevation: ",
7407+
label_ascent: "Total Ascent: ",
7408+
label_descent: "Total Descent: ",
73907409
//Editor
73917410
add_line_title: "Draw a Line",
73927411
add_photo_title: "Upload an Image",
@@ -9213,6 +9232,8 @@ function Waymark_Map_Viewer() {
92139232
"Total Length: ": waymark_js.lang.label_total_length,
92149233
"Max Elevation: ": waymark_js.lang.label_max_elevation,
92159234
"Min Elevation: ": waymark_js.lang.label_min_elevation,
9235+
"Total Ascent: ": waymark_js.lang.label_ascent,
9236+
"Total Descent: ": waymark_js.lang.label_descent,
92169237
});
92179238
Waymark_L.setLocale("waymark");
92189239

0 commit comments

Comments
 (0)