@raruto/leaflet-elevation 2.2.7 → 2.3.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/README.md CHANGED
@@ -35,8 +35,10 @@ _For a working example see one of the following demos:_
35
35
 
36
36
  - [autohide map](https://raruto.github.io/leaflet-elevation/examples/leaflet-elevation_hidden-map.html)
37
37
  - [autohide chart](https://raruto.github.io/leaflet-elevation/examples/leaflet-elevation_hidden-chart.html)
38
+ - [clear button](https://raruto.github.io/leaflet-elevation/examples/leaflet-elevation_clear-button.html)
38
39
  - [collapsible button](https://raruto.github.io/leaflet-elevation/examples/leaflet-elevation_close-button.html)
39
40
  - [custom summary](https://raruto.github.io/leaflet-elevation/examples/leaflet-elevation_custom-summary.html)
41
+ - [edge scale control](https://raruto.github.io/leaflet-elevation/examples/leaflet-elevation_edge-scale.html)
40
42
  - [follow marker](https://raruto.github.io/leaflet-elevation/examples/leaflet-elevation_follow-marker.html)
41
43
  - [layer almostover](https://raruto.github.io/leaflet-elevation/examples/leaflet-elevation_almost-over.html)
42
44
  - [slope chart](https://raruto.github.io/leaflet-elevation/examples/leaflet-elevation_slope-chart.html)
@@ -153,6 +155,9 @@ _For a working example see one of the following demos:_
153
155
 
154
156
  // Toggle "leaflet-distance-markers" integration
155
157
  distanceMarkers: false,
158
+
159
+ // Toggle "leaflet-edgescale" integration
160
+ edgeScale: false,
156
161
 
157
162
  // Toggle "leaflet-hotline" integration
158
163
  hotline: true,
@@ -195,19 +200,19 @@ _For a working example see one of the following demos:_
195
200
 
196
201
  ### Build Guide
197
202
 
198
- For those wishing to try cloning this repository into a local development folder (eg. /var/www):
203
+ Within your local development environment:
199
204
 
200
205
  ```shell
201
206
  git clone git@github.com:Raruto/leaflet-elevation.git
202
207
  cd ./leaflet-elevation
203
208
 
204
209
  npm i # install dependencies
205
- npm run watch # auto-generate "dist" files
210
+ npm run dev # start dev server at: http://localhost:8080
206
211
  npm run build # generate "dist" files (once)
207
- npm run test # test "spec" files (once)
212
+ npm run test # test all ".*spec.js" files (once)
208
213
  ```
209
214
 
210
- After that you can start developing inside the `src` and `test` folders (eg. open "http://localhost/leaflet-elevation/test" in your browser to preview changes). Check also [CONTRIBUTING.md](.github/CONTRIBUTING.md) file for some information about it.
215
+ After that you can start developing inside the `src` and `test` folders (eg. open "http://localhost:8080/test" in your browser to preview changes). Check also [CONTRIBUTING.md](.github/CONTRIBUTING.md) file for some information about it.
211
216
 
212
217
  ### FAQ
213
218
 
@@ -166,39 +166,39 @@
166
166
  var _ = /*#__PURE__*/Object.freeze({
167
167
  __proto__: null,
168
168
  Colors: Colors,
169
- formatTime: formatTime,
170
- formatDate: formatDate,
171
- saveFile: saveFile,
172
- drawCanvas: drawCanvas,
173
- coordPropsToMeta: coordPropsToMeta,
174
- parseNumeric: parseNumeric,
175
- parseDate: parseDate,
176
169
  addClass: addClass,
177
- removeClass: removeClass,
178
- toggleClass: toggleClass,
179
- replaceClass: replaceClass,
180
- style: style,
181
- toggleStyle: toggleStyle,
182
- setAttributes: setAttributes,
183
- toggleEvent: toggleEvent,
184
- create: create,
185
170
  append: append,
186
- insert: insert,
187
- select: select,
171
+ clamp: clamp,
172
+ coordPropsToMeta: coordPropsToMeta,
173
+ create: create,
174
+ drawCanvas: drawCanvas,
188
175
  each: each,
189
- randomId: randomId,
176
+ formatDate: formatDate,
177
+ formatTime: formatTime,
178
+ hasClass: hasClass,
179
+ iAvg: iAvg,
190
180
  iMax: iMax,
191
181
  iMin: iMin,
192
- iAvg: iAvg,
193
182
  iSum: iSum,
194
- on: on,
183
+ insert: insert,
195
184
  off: off,
196
- throttle: throttle,
197
- wrapNum: wrapNum,
198
- hasClass: hasClass,
185
+ on: on,
186
+ parseDate: parseDate,
187
+ parseNumeric: parseNumeric,
188
+ randomId: randomId,
189
+ removeClass: removeClass,
190
+ replaceClass: replaceClass,
199
191
  round: round,
200
- clamp: clamp,
201
- wrapDelta: wrapDelta
192
+ saveFile: saveFile,
193
+ select: select,
194
+ setAttributes: setAttributes,
195
+ style: style,
196
+ throttle: throttle,
197
+ toggleClass: toggleClass,
198
+ toggleEvent: toggleEvent,
199
+ toggleStyle: toggleStyle,
200
+ wrapDelta: wrapDelta,
201
+ wrapNum: wrapNum
202
202
  });
203
203
 
204
204
  var Options = {
@@ -215,6 +215,7 @@
215
215
  dragging: !L.Browser.mobile,
216
216
  downloadLink: 'link',
217
217
  elevationDiv: "#elevation-div",
218
+ edgeScale: { bar: true, icon: false, coords: false },
218
219
  followMarker: true,
219
220
  imperial: false,
220
221
  legend: true,
@@ -280,7 +281,6 @@
280
281
  decimalsY: 0,
281
282
  forceAxisBounds: false,
282
283
  interpolation: "curveLinear",
283
- skipNullZCoords: false,
284
284
  yAxisMax: undefined,
285
285
  yAxisMin: undefined,
286
286
  };
@@ -291,7 +291,7 @@
291
291
  }
292
292
 
293
293
  // Prevent CORS issues for relative locations (dynamic import)
294
- const baseURL = ((document.currentScript && document.currentScript.src) || (({ url: (typeof document === 'undefined' && typeof location === 'undefined' ? new (require('u' + 'rl').URL)('file:' + __filename).href : typeof document === 'undefined' ? location.href : (document.currentScript && document.currentScript.src || new URL('leaflet-elevation.js', document.baseURI).href)) }) && (typeof document === 'undefined' && typeof location === 'undefined' ? new (require('u' + 'rl').URL)('file:' + __filename).href : typeof document === 'undefined' ? location.href : (document.currentScript && document.currentScript.src || new URL('leaflet-elevation.js', document.baseURI).href)))).split("/").slice(0,-1).join("/") + '/';
294
+ const baseURL = ((document.currentScript && document.currentScript.src) || (({ url: (typeof document === 'undefined' && typeof location === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : typeof document === 'undefined' ? location.href : (document.currentScript && document.currentScript.src || new URL('leaflet-elevation.js', document.baseURI).href)) }) && (typeof document === 'undefined' && typeof location === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : typeof document === 'undefined' ? location.href : (document.currentScript && document.currentScript.src || new URL('leaflet-elevation.js', document.baseURI).href)))).split("/").slice(0,-1).join("/") + '/';
295
295
 
296
296
  const Elevation = L.Control.Elevation = L.Control.extend({
297
297
 
@@ -306,6 +306,7 @@
306
306
  __LALMOSTOVER: 'https://unpkg.com/leaflet-almostover@1.0.1/src/leaflet.almostover.js',
307
307
  __LHOTLINE: '../libs/leaflet-hotline.min.js',
308
308
  __LDISTANCEM: '../libs/leaflet-distance-marker.min.js',
309
+ __LEDGESCALE: '../libs/leaflet-edgescale.min.js',
309
310
  __LCHART: '../src/components/chart.js',
310
311
  __LMARKER: '../src/components/marker.js',
311
312
  __LSUMMARY: '../src/components/summary.js',
@@ -457,7 +458,10 @@
457
458
  */
458
459
  initialize: function(opts) {
459
460
 
460
- opts = L.setOptions(this, opts);
461
+ // opts = L.setOptions(this, opts);
462
+
463
+ // Fixes: https://github.com/Raruto/leaflet-elevation/pull/240
464
+ opts = L.setOptions(this, L.extend({}, structuredClone(Options), opts)); // "deep copy" nested objects (multiple charts)
461
465
 
462
466
  this._data = [];
463
467
  this._layers = L.featureGroup();
@@ -502,6 +506,7 @@
502
506
  case this.__LGEOMUTIL: condition = typeof L.GeometryUtil !== 'object'; break;
503
507
  case this.__LALMOSTOVER: condition = typeof L.Handler.AlmostOver !== 'function'; break;
504
508
  case this.__LDISTANCEM: condition = typeof L.DistanceMarkers !== 'function'; break;
509
+ case this.__LEDGESCALE: condition = typeof L.Control.EdgeScale !== 'function'; break;
505
510
  case this.__LHOTLINE: condition = typeof L.Hotline !== 'function'; break;
506
511
  }
507
512
  src = (src.startsWith('../') || src.startsWith('./') ? baseURL : '') + src;
@@ -704,6 +709,16 @@
704
709
  return this.options.distanceMarkers ? Promise.all([this.import(this.__LGEOMUTIL), this.import(this.__LDISTANCEM)]) : Promise.resolve();
705
710
  },
706
711
 
712
+ /**
713
+ * Initialize "L.Control.EdgeScale" integration
714
+ */
715
+ _initEdgeScale: function(map) {
716
+ return this.options.edgeScale ? Promise.all([this.import(this.__LEDGESCALE)])
717
+ .then(() => {
718
+ map.edgeScaleControl = map.edgeScaleControl || L.control.edgeScale('boolean' !== typeof this.options.edgeScale ? this.options.edgeScale : {}).addTo(map);
719
+ }) : Promise.resolve();
720
+ },
721
+
707
722
  _initHotLine: function(layer) {
708
723
  let prop = typeof this.options.hotline == 'string' ? this.options.hotline : 'elevation';
709
724
  return this.options.hotline ? this.import(this.__LHOTLINE)
@@ -749,6 +764,7 @@
749
764
  this._initHotLine(layer),
750
765
  this._initAlmostOverHandler(map, layer),
751
766
  this._initDistanceMarkers(),
767
+ this._initEdgeScale(map),
752
768
  ]).then(() => {
753
769
  if (this.options.polyline) {
754
770
  layer.addTo(map);
@@ -1273,10 +1289,10 @@
1273
1289
  }
1274
1290
 
1275
1291
  // prevent excessive variabile instanstations
1276
- let i, curr, prev, attr;
1292
+ let i, curr, prev, attr = props.attr || props.name;
1277
1293
 
1278
1294
  // save here a reference to last used point
1279
- let lastValid = null;
1295
+ let lastValid = {};
1280
1296
 
1281
1297
  // iteration
1282
1298
  this.on("elepoint_added", ({index, point}) => {
@@ -1284,42 +1300,33 @@
1284
1300
 
1285
1301
  prev = curr ?? this._data[i]; // same as: this._data[i > 0 ? i - 1 : i]
1286
1302
  curr = this._data[i];
1287
- attr = props.attr || props.name;
1303
+
1304
+ // retrieve point value
1305
+ curr[attr] = props.pointToAttr.call(this, point, i);
1288
1306
 
1289
1307
  // 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
- }
1308
+ if (i > 0 && isNaN(prev[attr])) {
1309
+ if (!isNaN(lastValid[attr]) && !isNaN(curr[attr])) {
1310
+ prev[attr] = (lastValid[attr] + curr[attr]) / 2;
1311
+ } else if (!isNaN(lastValid[attr])) {
1312
+ prev[attr] = lastValid[attr];
1313
+ } else if (!isNaN(curr[attr])) {
1314
+ prev[attr] = curr[attr];
1305
1315
  }
1306
- // update reference to last used point (ie. if it has data)
1307
- if (!isNaN(curr)) {
1308
- lastValid = curr;
1316
+ // update "yAttr" and "xAttr"
1317
+ if (props.meta) {
1318
+ prev[props.meta] = prev[attr];
1309
1319
  }
1310
1320
  }
1311
1321
 
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
- }
1322
+ // skip to next iteration for invalid or missing data (eg. i == 0)
1323
+ if (isNaN(curr[attr])) {
1324
+ return;
1321
1325
  }
1322
1326
 
1327
+ // update reference to last used point
1328
+ lastValid[attr] = curr[attr];
1329
+
1323
1330
  // Limit "crazy" delta values.
1324
1331
  if (props.deltaMax) {
1325
1332
  curr[attr] =wrapDelta(curr[attr], prev[attr], props.deltaMax);
@@ -1335,8 +1342,16 @@
1335
1342
  curr[attr] = round(curr[attr], props.decimals);
1336
1343
  }
1337
1344
 
1345
+ // update "track_info" stats (min, max, avg, ...)
1346
+ if (props.stats) {
1347
+ for (const key in props.stats) {
1348
+ let sname = (props.statsName || attr) + (key != '' ? '_' : '');
1349
+ this.track_info[sname + key] = props.stats[key].call(this, curr[attr], this.track_info[sname + key], this._data.length);
1350
+ }
1351
+ }
1352
+
1338
1353
  // update here some mixins (eg. complex "track_info" stuff)
1339
- if(props.onPointAdded) props.onPointAdded.call(this, curr[attr], i, point);
1354
+ if (props.onPointAdded) props.onPointAdded.call(this, curr[attr], i, point);
1340
1355
  });
1341
1356
  },
1342
1357
 
@@ -1354,7 +1369,6 @@
1354
1369
  name,
1355
1370
  attr,
1356
1371
  required,
1357
- skipNull,
1358
1372
  deltaMax,
1359
1373
  clampRange,
1360
1374
  decimals,
@@ -1379,7 +1393,7 @@
1379
1393
  this._registerDataAttribute({
1380
1394
  name,
1381
1395
  attr,
1382
- skipNull,
1396
+ meta,
1383
1397
  deltaMax,
1384
1398
  clampRange,
1385
1399
  decimals,