@raruto/leaflet-elevation 2.1.1 → 2.2.2

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
@@ -26,7 +26,7 @@ _For a working example see one of the following demos:_
26
26
  - [loading multiple maps](https://raruto.github.io/leaflet-elevation/examples/leaflet-elevation_multiple-maps.html)
27
27
  - [translating plugin labels](https://raruto.github.io/leaflet-elevation/examples/leaflet-elevation_i18n-strings.html)
28
28
  - [using custom colors](https://raruto.github.io/leaflet-elevation/examples/leaflet-elevation_custom-theme.html)
29
- - [using .gpx extensions (cadence + heart)](https://raruto.github.io/leaflet-elevation/examples/leaflet-elevation_extended-ui.html)
29
+ - [using .gpx extensions (cadence, heart, pace)](https://raruto.github.io/leaflet-elevation/examples/leaflet-elevation_extended-ui.html)
30
30
  - [using .gpx waypoint icons](https://raruto.github.io/leaflet-elevation/examples/leaflet-elevation_gpx-waypoints.html)
31
31
  - [using .geojson waypoint icons](https://raruto.github.io/leaflet-elevation/examples/leaflet-elevation_geojson-waypoints.html)
32
32
 
@@ -63,7 +63,7 @@ _For a working example see one of the following demos:_
63
63
 
64
64
  <!-- leaflet-ui -->
65
65
  <script src="https://unpkg.com/leaflet@1.7.1/dist/leaflet.js"></script>
66
- <script src="https://unpkg.com/leaflet-ui@0.5.4/dist/leaflet-ui.js"></script>
66
+ <script src="https://unpkg.com/leaflet-ui@0.5.5/dist/leaflet-ui.js"></script>
67
67
 
68
68
  <!-- leaflet-elevation -->
69
69
  <link rel="stylesheet" href="https://unpkg.com/@raruto/leaflet-elevation/dist/leaflet-elevation.css" />
@@ -124,15 +124,15 @@ _For a working example see one of the following demos:_
124
124
  // Speed chart profile: true || "summary" || "disabled" || false
125
125
  speed: false,
126
126
 
127
+ // Altitude chart profile: true || "summary" || "disabled" || false
128
+ altitude: true,
129
+
127
130
  // Display time info: true || "summary" || false
128
- time: false,
131
+ time: true,
129
132
 
130
- // Display distance info: true || "summary"
133
+ // Display distance info: true || "summary" || false
131
134
  distance: true,
132
135
 
133
- // Display altitude info: true || "summary"
134
- altitude: true,
135
-
136
136
  // Summary track info style: "inline" || "multiline" || false
137
137
  summary: 'multiline',
138
138
 
@@ -196,7 +196,7 @@ git clone git@github.com:Raruto/leaflet-elevation.git
196
196
  cd ./leaflet-elevation
197
197
 
198
198
  npm i # install dependencies
199
- npm run dev # auto-generate "dist" files
199
+ npm run watch # auto-generate "dist" files
200
200
  npm run build # generate "dist" files (once)
201
201
  npm run test # test "spec" files (once)
202
202
  ```
@@ -218,7 +218,7 @@
218
218
  followMarker: true,
219
219
  imperial: false,
220
220
  legend: true,
221
- handlers: [],
221
+ handlers: ["Distance", "Time", "Altitude", "Slope", "Speed", "Acceleration"],
222
222
  hotline: 'elevation',
223
223
  marker: 'elevation-line',
224
224
  markerIcon: L.divIcon({
@@ -247,7 +247,7 @@
247
247
  summary: 'inline',
248
248
  slope: false,
249
249
  speed: false,
250
- time: false,
250
+ time: true,
251
251
  timeFactor: 3600,
252
252
  timestamps: false,
253
253
  trkStart: L.circleMarker([0,0], { className: 'start-marker', radius: 6, weight: 2, color: '#fff', fillColor: '#00d800', fillOpacity: 1, interactive: false }),
@@ -314,10 +314,14 @@
314
314
  addData: function(d, layer) {
315
315
  this.import(this.__D3)
316
316
  .then(() => {
317
- layer = layer ?? (d.on && d);
318
- this._addData(d);
319
- this._addLayer(layer);
320
- this._fireEvt("eledata_added", { data: d, layer: layer, track_info: this.track_info });
317
+ if (this._modulesLoaded) {
318
+ layer = layer ?? (d.on && d);
319
+ this._addData(d);
320
+ this._addLayer(layer);
321
+ this._fireEvt("eledata_added", { data: d, layer: layer, track_info: this.track_info });
322
+ } else {
323
+ this.once('modules_loaded', () => this.addData(d,layer));
324
+ }
321
325
  });
322
326
  },
323
327
 
@@ -516,22 +520,14 @@
516
520
 
517
521
  if (!this.eleDiv) this.eleDiv = container;
518
522
 
519
- let modules = [
520
- "Distance",
521
- "Time",
522
- "Altitude",
523
- "Slope",
524
- "Speed",
525
- "Acceleration",
526
- ...this.options.handlers
527
- ].filter(m => false !== this.options[typeof m == "string" && m.toLowerCase()]);
528
-
529
- this._loadModules(modules).then(() => { // Inject here required modules (data handlers)
523
+ this._loadModules(this.options.handlers).then(() => { // Inject here required modules (data handlers)
530
524
  this._initChart(container);
531
525
  this._initButton(container);
532
526
  this._initSummary(container);
533
527
  this._initMarker(map);
534
528
  this._initLayer(map);
529
+ this._modulesLoaded = true;
530
+ this.fire('modules_loaded');
535
531
  });
536
532
 
537
533
  this.fire('add');
@@ -600,7 +596,7 @@
600
596
  if (geom) {
601
597
  switch (geom.type) {
602
598
  case 'LineString': return this._addGeoJSONData(geom.coordinates, d.properties);
603
- case 'MultiLineString': return each(geom.coordinates, (coords, i) => this._addGeoJSONData(coords, d.properties, i));
599
+ case 'MultiLineString': return each(geom.coordinates, (coords, i) => this._addGeoJSONData(coords, d.properties, i));
604
600
  case 'Point':
605
601
  default: return console.warn('Unsopperted GeoJSON feature geometry type:' + geom.type);
606
602
  }
@@ -1014,14 +1010,12 @@
1014
1010
  // First map known classnames (eg. "Altitude" --> L.Control.Elevation.Altitude)
1015
1011
  handlers = handlers.map((h) => typeof h === 'string' && typeof Elevation[h] !== "undefined" ? Elevation[h] : h);
1016
1012
  // Then load optional classes and custom imports (eg. "Cadence" --> import('../src/handlers/cadence.js'))
1017
- let modules = handlers
1018
- .filter(h => typeof h === 'string' || h instanceof Promise)
1019
- .map(file => file instanceof Promise ? file : this.import(this.__modulesFolder + file.toLowerCase() + '.js'));
1013
+ let modules = handlers.map(file => (typeof file === 'string' && this.import(this.__modulesFolder + file.toLowerCase() + '.js')) || (file instanceof Promise && file) || Promise.resolve());
1020
1014
  return Promise.all(modules).then((m) => {
1021
- each(m, (exported) => {
1022
- let fn = Object.keys(exported)[0];
1015
+ each(m, (exported, i) => {
1016
+ let fn = exported && Object.keys(exported)[0];
1023
1017
  if (fn) {
1024
- handlers[fn] = Elevation[fn] = (Elevation[fn] ?? exported[fn]);
1018
+ handlers[i] = Elevation[fn] = (Elevation[fn] ?? exported[fn]);
1025
1019
  }
1026
1020
  });
1027
1021
  each(handlers, h => ["function", "object"].includes(typeof h) && this._registerHandler(h));
@@ -1314,7 +1308,7 @@
1314
1308
  if (props.stats) {
1315
1309
  for (const key in props.stats) {
1316
1310
  let sname = (props.statsName || attr) + (key != '' ? '_' : '');
1317
- this.track_info[sname + key] = props.stats[key].call(this, curr[attr], this.track_info[sname + key], index);
1311
+ this.track_info[sname + key] = props.stats[key].call(this, curr[attr], this.track_info[sname + key], this._data.length);
1318
1312
  }
1319
1313
  }
1320
1314