@raruto/leaflet-elevation 1.8.7 → 1.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@raruto/leaflet-elevation",
3
- "version": "1.8.7",
3
+ "version": "1.9.0",
4
4
  "description": "A Leaflet plugin that allows to add elevation profiles using d3js",
5
5
  "main": "dist/leaflet-elevation.min.js",
6
6
  "module": "src/index.js",
package/src/components.js CHANGED
@@ -496,8 +496,8 @@ export const Chart = ({
496
496
  const panes = {
497
497
  grid : g.append("g").attr("class", "grid"),
498
498
  area : g.append('g').attr("class", "area"),
499
- point : g.append('g').attr("class", "point"),
500
499
  axis : g.append('g').attr("class", "axis"),
500
+ point : g.append('g').attr("class", "point"),
501
501
  brush : g.append("g").attr("class", "brush"),
502
502
  tooltip: g.append("g").attr("class", "tooltip").attr('display', 'none'),
503
503
  ruler : g.append('g').attr('class', 'ruler'),
package/src/control.js CHANGED
@@ -17,7 +17,7 @@ export const Elevation = L.Control.Elevation = L.Control.extend({
17
17
  __TOGEOJSON: 'https://unpkg.com/@tmcw/togeojson@4.5.0/dist/togeojson.umd.js',
18
18
  __LGEOMUTIL: 'https://unpkg.com/leaflet-geometryutil@0.9.3/src/leaflet.geometryutil.js',
19
19
  __LALMOSTOVER: 'https://unpkg.com/leaflet-almostover@1.0.1/src/leaflet.almostover.js',
20
- __LDISTANCEM: 'https://unpkg.com/@raruto/leaflet-elevation@1.8.7/libs/leaflet-distance-marker.min.js',
20
+ __LDISTANCEM: 'https://unpkg.com/@raruto/leaflet-elevation@1.9.0/libs/leaflet-distance-marker.min.js',
21
21
 
22
22
  /*
23
23
  * Add data to the diagram either from GPX or GeoJSON and update the axis domain and data
@@ -345,12 +345,16 @@ export const Elevation = L.Control.Elevation = L.Control.extend({
345
345
 
346
346
  // "alt" property is generated inside "leaflet"
347
347
  if ("alt" in point) point.meta.ele = point.alt;
348
-
348
+
349
349
  // "coordinateProperties" property is generated inside "@tmcw/toGeoJSON"
350
- if (properties.coordinateProperties) {
351
- let props = properties.coordinateProperties;
352
- if("times" in props) point.meta.time = new Date(Date.parse(props.times[i]));
353
- if("heart" in props) point.meta.hr = parseInt(props.heart[i]);
350
+ let props = (properties && properties.coordinateProperties) || properties;
351
+ if (props) {
352
+ if("coordTimes" in props) point.meta.time = new Date(Date.parse(props.coordTimes[i]));
353
+ else if("times" in props) point.meta.time = new Date(Date.parse(props.times[i]));
354
+ else if("time" in props) point.meta.time = new Date(Date.parse((typeof props.time === 'object' ? props.time[i] : props.time)));
355
+ if ("heartRates" in props) point.meta.hr = parseInt(props.heartRates[i]);
356
+ else if("heartRate" in props) point.meta.hr = parseInt((typeof props.heartRate === 'object' ? props.heartRate[i] : props.heartRate));
357
+ else if("heart" in props) point.meta.hr = parseInt((typeof props.heart === 'object' ? props.heart[i] : props.heart));
354
358
  // TODO: ask to "@tmcw/toGeoJSON" for "cadence" and "temperature" implementation
355
359
  }
356
360
 
@@ -1063,16 +1067,12 @@ export const Elevation = L.Control.Elevation = L.Control.extend({
1063
1067
  * Toggle chart data on legend click
1064
1068
  */
1065
1069
  _toggleChartHandler: function(e) {
1066
- let { path, name, enabled } = e;
1070
+ let { name, enabled } = e;
1067
1071
 
1068
1072
  this._chartEnabled = this._chart._hasActiveLayers();
1069
1073
 
1070
1074
  // toggle layer visibility on empty chart
1071
- this._layers.eachLayer(layer => {
1072
- let node = layer.getElement && layer.getElement();
1073
- _.toggleClass(node, this.options.polyline.className + ' ' + this.options.theme, this._chartEnabled);
1074
- }
1075
- );
1075
+ this._layers.eachLayer(layer => _.toggleClass(layer.getElement && layer.getElement(), this.options.polyline.className + ' ' + this.options.theme, this._chartEnabled));
1076
1076
 
1077
1077
  // toggle option value (eg. altitude = { 'disabled' || 'disabled' })
1078
1078
  this.options[name] = !enabled && this.options[name] == 'disabled' ? 'enabled' : 'disabled';
@@ -1,107 +0,0 @@
1
- /*
2
- * Copyright (c) 2020, GPL-3.0+ Project, Gérald Niel, Raruto
3
- *
4
- * This file is free software: you may copy, redistribute and/or modify it
5
- * under the terms of the GNU General Public License as published by the
6
- * Free Software Foundation, either version 2 of the License, or (at your
7
- * option) any later version.
8
- *
9
- * This file is distributed in the hope that it will be useful, but
10
- * WITHOUT ANY WARRANTY; without even the implied warranty of
11
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12
- * General Public License for more details.
13
- *
14
- * You should have received a copy of the GNU General Public License
15
- * along with this program. If not, see .
16
- */
17
-
18
- L.Control.Elevation.addInitHook(function() {
19
-
20
- this.on("eledata_updated", function(e) {
21
- let data = this._data;
22
- let i = e.index;
23
- let z = data[i].z;
24
-
25
- let curr = data[i].latlng;
26
- let prev = i > 0 ? data[i - 1].latlng : curr;
27
-
28
- let delta = curr.distanceTo(prev) * this._distanceFactor;
29
-
30
- // Slope / Gain
31
- let tAsc = this._tAsc || 0; // Total Ascent
32
- let tDes = this._tDes || 0; // Total Descent
33
- let sMax = this._sMax || 0; // Slope Max
34
- let sMin = this._sMin || 0; // Slope Min
35
- let diff = 0;
36
- let slope = 0;
37
-
38
- if (!isNaN(z)) {
39
- // diff height between actual and previous point
40
- diff = i > 0 ? z - data[i - 1].z : 0;
41
- if (diff > 0) tAsc += diff;
42
- if (diff < 0) tDes -= diff;
43
- // slope in % = ( height / length ) * 100
44
- slope = delta !== 0 ? Math.round((diff / delta) * 10000) / 100 : 0;
45
- // apply slope to the previous point because we will
46
- // ascent or desent, so the slope is in the fist point
47
- if (i > 0) data[i - 1].slope = slope;
48
- sMax = slope > sMax ? slope : sMax;
49
- sMin = slope < sMin ? slope : sMin;
50
- }
51
-
52
- data[i].slope = slope;
53
-
54
- this.track_info = this.track_info || {};
55
- this.track_info.ascent = this._tAsc = tAsc;
56
- this.track_info.descent = this._tDes = tDes;
57
- this.track_info.slope_max = this._sMax = sMax;
58
- this.track_info.slope_min = this._sMin = sMin;
59
- });
60
-
61
- if (!this.options.extendedUI) return;
62
-
63
- this.on("elechart_change", function(e) {
64
- let item = e.data;
65
- let xCoordinate = e.xCoord;
66
-
67
- if (!this._focuslabelSlope || !this._focuslabelSlope.property('isConnected')) {
68
- this._focuslabelSlope = this._focuslabeltext.insert("svg:tspan", ".mouse-focus-label-x")
69
- .attr("class", "mouse-focus-label-slope")
70
- .attr("dy", "1.5em");
71
- }
72
-
73
- this._focuslabelSlope.text(item.slope + "%");
74
-
75
- if (!this._mouseSlopeFocusLabel) {
76
- this._mouseSlopeFocusLabel = this._mouseHeightFocusLabel.append("svg:tspan")
77
- .attr("class", "height-focus-slope ");
78
- }
79
-
80
- this._mouseHeightFocusLabelY
81
- .attr("dy", "-1.5em");
82
- this._focuslabelX
83
- .attr("dy", "1.5em");
84
-
85
- this._mouseSlopeFocusLabel
86
- .attr("dy", "1.5em")
87
- .text(Math.round(item.slope) + "%");
88
-
89
- });
90
-
91
- this.on("elechart_summary", function() {
92
- this.summaryDiv.querySelector('.minele').insertAdjacentHTML('afterend', '<span class="ascent"><span class="summarylabel">' + L._("Total Ascent: ") + '</span><span class="summaryvalue">' + Math.round(this.track_info.ascent) + '&nbsp;' +
93
- this._yLabel +
94
- '</span></span>' + '<span class="descent"><span class="summarylabel">' + L._("Total Descent: ") + '</span><span class="summaryvalue">' + Math.round(this.track_info.descent) + '&nbsp;' + this._yLabel +
95
- '</span></span>' + '<span class="minslope"><span class="summarylabel">' + L._("Min Slope: ") + '</span><span class="summaryvalue">' + this.track_info.slope_min + '&nbsp;' + '%' +
96
- '</span></span>' + '<span class="maxslope"><span class="summarylabel">' + L._("Max Slope: ") + '</span><span class="summaryvalue">' + this.track_info.slope_max + '&nbsp;' + '%' +
97
- '</span></span>');
98
- });
99
-
100
- this.on("eledata_clear", function() {
101
- this._sMax = null;
102
- this._sMin = null;
103
- this._tAsc = null;
104
- this._tDes = null;
105
- });
106
-
107
- });
@@ -1,5 +0,0 @@
1
- 'use strict';L.Control.Elevation.addInitHook(function(){this.on("eledata_updated",function(e){let data=this._data;let i=e.index;let z=data[i].z;let curr=data[i].latlng;let prev=i>0?data[i-1].latlng:curr;let delta=curr.distanceTo(prev)*this._distanceFactor;let tAsc=this._tAsc||0;let tDes=this._tDes||0;let sMax=this._sMax||0;let sMin=this._sMin||0;let diff=0;let slope=0;if(!isNaN(z)){diff=i>0?z-data[i-1].z:0;if(diff>0)tAsc+=diff;if(diff<0)tDes-=diff;slope=delta!==0?Math.round(diff/delta*1E4)/100:0;
2
- if(i>0)data[i-1].slope=slope;sMax=slope>sMax?slope:sMax;sMin=slope<sMin?slope:sMin}data[i].slope=slope;this.track_info=this.track_info||{};this.track_info.ascent=this._tAsc=tAsc;this.track_info.descent=this._tDes=tDes;this.track_info.slope_max=this._sMax=sMax;this.track_info.slope_min=this._sMin=sMin});if(!this.options.extendedUI)return;this.on("elechart_change",function(e){let item=e.data;let xCoordinate=e.xCoord;if(!this._focuslabelSlope||!this._focuslabelSlope.property("isConnected"))this._focuslabelSlope=
3
- this._focuslabeltext.insert("svg:tspan",".mouse-focus-label-x").attr("class","mouse-focus-label-slope").attr("dy","1.5em");this._focuslabelSlope.text(item.slope+"%");if(!this._mouseSlopeFocusLabel)this._mouseSlopeFocusLabel=this._mouseHeightFocusLabel.append("svg:tspan").attr("class","height-focus-slope ");this._mouseHeightFocusLabelY.attr("dy","-1.5em");this._focuslabelX.attr("dy","1.5em");this._mouseSlopeFocusLabel.attr("dy","1.5em").text(Math.round(item.slope)+"%")});this.on("elechart_summary",
4
- function(){this.summaryDiv.querySelector(".minele").insertAdjacentHTML("afterend",'<span class="ascent"><span class="summarylabel">'+L._("Total Ascent: ")+'</span><span class="summaryvalue">'+Math.round(this.track_info.ascent)+"&nbsp;"+this._yLabel+"</span></span>"+'<span class="descent"><span class="summarylabel">'+L._("Total Descent: ")+'</span><span class="summaryvalue">'+Math.round(this.track_info.descent)+"&nbsp;"+this._yLabel+"</span></span>"+'<span class="minslope"><span class="summarylabel">'+
5
- L._("Min Slope: ")+'</span><span class="summaryvalue">'+this.track_info.slope_min+"&nbsp;"+"%"+"</span></span>"+'<span class="maxslope"><span class="summarylabel">'+L._("Max Slope: ")+'</span><span class="summaryvalue">'+this.track_info.slope_max+"&nbsp;"+"%"+"</span></span>")});this.on("eledata_clear",function(){this._sMax=null;this._sMin=null;this._tAsc=null;this._tDes=null})});