@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.
@@ -280,7 +280,6 @@
280
280
  decimalsY: 0,
281
281
  forceAxisBounds: false,
282
282
  interpolation: "curveLinear",
283
- skipNullZCoords: false,
284
283
  yAxisMax: undefined,
285
284
  yAxisMin: undefined,
286
285
  };
@@ -1273,10 +1272,10 @@
1273
1272
  }
1274
1273
 
1275
1274
  // prevent excessive variabile instanstations
1276
- let i, curr, prev, attr;
1275
+ let i, curr, prev, attr = props.attr || props.name;
1277
1276
 
1278
1277
  // save here a reference to last used point
1279
- let lastValid = null;
1278
+ let lastValid = {};
1280
1279
 
1281
1280
  // iteration
1282
1281
  this.on("elepoint_added", ({index, point}) => {
@@ -1284,42 +1283,33 @@
1284
1283
 
1285
1284
  prev = curr ?? this._data[i]; // same as: this._data[i > 0 ? i - 1 : i]
1286
1285
  curr = this._data[i];
1287
- attr = props.attr || props.name;
1286
+
1287
+ // retrieve point value
1288
+ curr[attr] = props.pointToAttr.call(this, point, i);
1288
1289
 
1289
1290
  // check and fix missing data on last added point
1290
- if (props.skipNull === false) {
1291
- let curr = this._data[i][attr];
1292
- if(i > 0) {
1293
- let prev = this._data[i - 1][attr];
1294
- if (isNaN(prev)) {
1295
- if (!isNaN(lastValid) && !isNaN(curr)) {
1296
- prev = (lastValid + curr) / 2;
1297
- } else if (!isNaN(lastValid)) {
1298
- prev = lastValid;
1299
- } else if (!isNaN(curr)) {
1300
- prev = curr;
1301
- }
1302
- if (!isNaN(prev)) return this._data.splice(i - 1, 1);
1303
- this._data[i - 1][attr] = prev;
1304
- }
1291
+ if (i > 0 && isNaN(prev[attr])) {
1292
+ if (!isNaN(lastValid[attr]) && !isNaN(curr[attr])) {
1293
+ prev[attr] = (lastValid[attr] + curr[attr]) / 2;
1294
+ } else if (!isNaN(lastValid[attr])) {
1295
+ prev[attr] = lastValid[attr];
1296
+ } else if (!isNaN(curr[attr])) {
1297
+ prev[attr] = curr[attr];
1305
1298
  }
1306
- // update reference to last used point (ie. if it has data)
1307
- if (!isNaN(curr)) {
1308
- lastValid = curr;
1299
+ // update "yAttr" and "xAttr"
1300
+ if (props.meta) {
1301
+ prev[props.meta] = prev[attr];
1309
1302
  }
1310
1303
  }
1311
1304
 
1312
- // retrieve point value
1313
- curr[attr] = props.pointToAttr.call(this, point, i);
1314
-
1315
- // update "track_info" stats (min, max, avg, ...)
1316
- if (props.stats) {
1317
- for (const key in props.stats) {
1318
- let sname = (props.statsName || attr) + (key != '' ? '_' : '');
1319
- this.track_info[sname + key] = props.stats[key].call(this, curr[attr], this.track_info[sname + key], this._data.length);
1320
- }
1305
+ // skip to next iteration for invalid or missing data (eg. i == 0)
1306
+ if (isNaN(curr[attr])) {
1307
+ return;
1321
1308
  }
1322
1309
 
1310
+ // update reference to last used point
1311
+ lastValid[attr] = curr[attr];
1312
+
1323
1313
  // Limit "crazy" delta values.
1324
1314
  if (props.deltaMax) {
1325
1315
  curr[attr] =wrapDelta(curr[attr], prev[attr], props.deltaMax);
@@ -1335,8 +1325,16 @@
1335
1325
  curr[attr] = round(curr[attr], props.decimals);
1336
1326
  }
1337
1327
 
1328
+ // update "track_info" stats (min, max, avg, ...)
1329
+ if (props.stats) {
1330
+ for (const key in props.stats) {
1331
+ let sname = (props.statsName || attr) + (key != '' ? '_' : '');
1332
+ this.track_info[sname + key] = props.stats[key].call(this, curr[attr], this.track_info[sname + key], this._data.length);
1333
+ }
1334
+ }
1335
+
1338
1336
  // update here some mixins (eg. complex "track_info" stuff)
1339
- if(props.onPointAdded) props.onPointAdded.call(this, curr[attr], i, point);
1337
+ if (props.onPointAdded) props.onPointAdded.call(this, curr[attr], i, point);
1340
1338
  });
1341
1339
  },
1342
1340
 
@@ -1354,7 +1352,6 @@
1354
1352
  name,
1355
1353
  attr,
1356
1354
  required,
1357
- skipNull,
1358
1355
  deltaMax,
1359
1356
  clampRange,
1360
1357
  decimals,
@@ -1379,7 +1376,7 @@
1379
1376
  this._registerDataAttribute({
1380
1377
  name,
1381
1378
  attr,
1382
- skipNull,
1379
+ meta,
1383
1380
  deltaMax,
1384
1381
  clampRange,
1385
1382
  decimals,