@raruto/leaflet-elevation 2.2.7 → 2.2.8

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/src/control.js CHANGED
@@ -990,10 +990,10 @@ export const Elevation = L.Control.Elevation = L.Control.extend({
990
990
  }
991
991
 
992
992
  // prevent excessive variabile instanstations
993
- let i, curr, prev, attr;
993
+ let i, curr, prev, attr = props.attr || props.name;
994
994
 
995
995
  // save here a reference to last used point
996
- let lastValid = null;
996
+ let lastValid = {};
997
997
 
998
998
  // iteration
999
999
  this.on("elepoint_added", ({index, point}) => {
@@ -1001,42 +1001,33 @@ export const Elevation = L.Control.Elevation = L.Control.extend({
1001
1001
 
1002
1002
  prev = curr ?? this._data[i]; // same as: this._data[i > 0 ? i - 1 : i]
1003
1003
  curr = this._data[i];
1004
- attr = props.attr || props.name;
1004
+
1005
+ // retrieve point value
1006
+ curr[attr] = props.pointToAttr.call(this, point, i);
1005
1007
 
1006
1008
  // check and fix missing data on last added point
1007
- if (props.skipNull === false) {
1008
- let curr = this._data[i][attr];
1009
- if(i > 0) {
1010
- let prev = this._data[i - 1][attr];
1011
- if (isNaN(prev)) {
1012
- if (!isNaN(lastValid) && !isNaN(curr)) {
1013
- prev = (lastValid + curr) / 2;
1014
- } else if (!isNaN(lastValid)) {
1015
- prev = lastValid;
1016
- } else if (!isNaN(curr)) {
1017
- prev = curr;
1018
- }
1019
- if (!isNaN(prev)) return this._data.splice(i - 1, 1);
1020
- this._data[i - 1][attr] = prev;
1021
- }
1009
+ if (i > 0 && isNaN(prev[attr])) {
1010
+ if (!isNaN(lastValid[attr]) && !isNaN(curr[attr])) {
1011
+ prev[attr] = (lastValid[attr] + curr[attr]) / 2;
1012
+ } else if (!isNaN(lastValid[attr])) {
1013
+ prev[attr] = lastValid[attr];
1014
+ } else if (!isNaN(curr[attr])) {
1015
+ prev[attr] = curr[attr];
1022
1016
  }
1023
- // update reference to last used point (ie. if it has data)
1024
- if (!isNaN(curr)) {
1025
- lastValid = curr;
1017
+ // update "yAttr" and "xAttr"
1018
+ if (props.meta) {
1019
+ prev[props.meta] = prev[attr];
1026
1020
  }
1027
1021
  }
1028
1022
 
1029
- // retrieve point value
1030
- curr[attr] = props.pointToAttr.call(this, point, i);
1031
-
1032
- // update "track_info" stats (min, max, avg, ...)
1033
- if (props.stats) {
1034
- for (const key in props.stats) {
1035
- let sname = (props.statsName || attr) + (key != '' ? '_' : '');
1036
- this.track_info[sname + key] = props.stats[key].call(this, curr[attr], this.track_info[sname + key], this._data.length);
1037
- }
1023
+ // skip to next iteration for invalid or missing data (eg. i == 0)
1024
+ if (isNaN(curr[attr])) {
1025
+ return;
1038
1026
  }
1039
1027
 
1028
+ // update reference to last used point
1029
+ lastValid[attr] = curr[attr];
1030
+
1040
1031
  // Limit "crazy" delta values.
1041
1032
  if (props.deltaMax) {
1042
1033
  curr[attr] =_.wrapDelta(curr[attr], prev[attr], props.deltaMax);
@@ -1052,8 +1043,16 @@ export const Elevation = L.Control.Elevation = L.Control.extend({
1052
1043
  curr[attr] = _.round(curr[attr], props.decimals);
1053
1044
  }
1054
1045
 
1046
+ // update "track_info" stats (min, max, avg, ...)
1047
+ if (props.stats) {
1048
+ for (const key in props.stats) {
1049
+ let sname = (props.statsName || attr) + (key != '' ? '_' : '');
1050
+ this.track_info[sname + key] = props.stats[key].call(this, curr[attr], this.track_info[sname + key], this._data.length);
1051
+ }
1052
+ }
1053
+
1055
1054
  // update here some mixins (eg. complex "track_info" stuff)
1056
- if(props.onPointAdded) props.onPointAdded.call(this, curr[attr], i, point);
1055
+ if (props.onPointAdded) props.onPointAdded.call(this, curr[attr], i, point);
1057
1056
  });
1058
1057
  },
1059
1058
 
@@ -1071,7 +1070,6 @@ export const Elevation = L.Control.Elevation = L.Control.extend({
1071
1070
  name,
1072
1071
  attr,
1073
1072
  required,
1074
- skipNull,
1075
1073
  deltaMax,
1076
1074
  clampRange,
1077
1075
  decimals,
@@ -1096,7 +1094,7 @@ export const Elevation = L.Control.Elevation = L.Control.extend({
1096
1094
  this._registerDataAttribute({
1097
1095
  name,
1098
1096
  attr,
1099
- skipNull,
1097
+ meta,
1100
1098
  deltaMax,
1101
1099
  clampRange,
1102
1100
  decimals,
@@ -17,7 +17,7 @@ export function Acceleration() {
17
17
  pointToAttr: (_, i) => {
18
18
  let dv = (this._data[i].speed - this._data[i > 0 ? i - 1 : i].speed) * (1000 / opts.timeFactor);
19
19
  let dt = (this._data[i].time - this._data[i > 0 ? i - 1 : i].time) / 1000;
20
- return dt > 0 ? Math.abs((dv / dt)) * opts.accelerationFactor : 0;
20
+ return dt > 0 ? Math.abs((dv / dt)) * opts.accelerationFactor : NaN;
21
21
  },
22
22
  stats: { max: _.iMax, min: _.iMin, avg: _.iAvg },
23
23
  scale: {
@@ -17,7 +17,6 @@ export function Altitude() {
17
17
  meta: 'z',
18
18
  unit: altitude.label,
19
19
  statsName: 'elevation',
20
- skipNull: this.options.skipNullZCoords,
21
20
  deltaMax: this.options.altitudeDeltaMax,
22
21
  clampRange: this.options.altitudeRange,
23
22
  // init: ({point}) => {
@@ -17,7 +17,7 @@ export function Pace() {
17
17
  pointToAttr: (_, i) => {
18
18
  let dx = (this._data[i].dist - this._data[i > 0 ? i - 1 : i].dist) * 1000;
19
19
  let dt = this._data[i].time - this._data[ i > 0 ? i - 1 : i].time;
20
- return dx > 0 ? Math.abs((dt / dx) / opts.paceFactor) : 0;
20
+ return dx > 0 ? Math.abs((dt / dx) / opts.paceFactor) : NaN;
21
21
  },
22
22
  stats: { max: _.iMax, min: _.iMin, avg: _.iAvg },
23
23
  scale : (this.options.pace && this.options.pace != "summary") && {
@@ -17,7 +17,7 @@ export function Slope() {
17
17
  pointToAttr: (_, i) => { // slope in % = ( dy / dx ) * 100;
18
18
  let dx = (this._data[i].dist - this._data[i > 0 ? i - 1 : i].dist) * 1000;
19
19
  let dy = this._data[i][this.options.yAttr] - this._data[i > 0 ? i - 1 : i][this.options.yAttr];
20
- return (!isNaN(dy) && dx !== 0) ? (dy / dx) * 100 : 0;
20
+ return dx !== 0 ? (dy / dx) * 100 : NaN;
21
21
  },
22
22
  onPointAdded: (_, i) => {
23
23
  let dz = this._data[i][this.options.yAttr] - this._data[i > 0 ? i - 1 : i][this.options.yAttr];
@@ -18,7 +18,7 @@ export function Speed() {
18
18
  pointToAttr: (_, i) => {
19
19
  let dx = (this._data[i].dist - this._data[i > 0 ? i - 1 : i].dist) * 1000;
20
20
  let dt = this._data[i].time - this._data[ i > 0 ? i - 1 : i].time;
21
- return dt > 0 ? Math.abs((dx / dt) * opts.timeFactor) * opts.speedFactor : 0;
21
+ return dt > 0 ? Math.abs((dx / dt) * opts.timeFactor) * opts.speedFactor : NaN;
22
22
  },
23
23
  stats: { max: _.iMax, min: _.iMin, avg: _.iAvg },
24
24
  scale : (this.options.speed && this.options.speed != "summary") && {
package/src/options.js CHANGED
@@ -79,7 +79,6 @@ export var Options = {
79
79
  decimalsY: 0,
80
80
  forceAxisBounds: false,
81
81
  interpolation: "curveLinear",
82
- skipNullZCoords: false,
83
82
  yAxisMax: undefined,
84
83
  yAxisMin: undefined,
85
84
  };