@raruto/leaflet-elevation 2.1.0 → 2.2.1

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
@@ -23,9 +23,10 @@ _For a working example see one of the following demos:_
23
23
  - [loading individual .gpx tracks](https://raruto.github.io/leaflet-elevation/examples/leaflet-elevation_toggable-tracks.html)
24
24
  - [loading multiple .gpx tracks (hover to toggle)](https://raruto.github.io/leaflet-elevation/examples/leaflet-elevation_hoverable-tracks.html)
25
25
  - [loading multiple .gpx tracks (click to toggle)](https://raruto.github.io/leaflet-elevation/examples/leaflet-elevation_toggable-charts.html)
26
+ - [loading multiple maps](https://raruto.github.io/leaflet-elevation/examples/leaflet-elevation_multiple-maps.html)
26
27
  - [translating plugin labels](https://raruto.github.io/leaflet-elevation/examples/leaflet-elevation_i18n-strings.html)
27
28
  - [using custom colors](https://raruto.github.io/leaflet-elevation/examples/leaflet-elevation_custom-theme.html)
28
- - [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)
29
30
  - [using .gpx waypoint icons](https://raruto.github.io/leaflet-elevation/examples/leaflet-elevation_gpx-waypoints.html)
30
31
  - [using .geojson waypoint icons](https://raruto.github.io/leaflet-elevation/examples/leaflet-elevation_geojson-waypoints.html)
31
32
 
@@ -62,7 +63,7 @@ _For a working example see one of the following demos:_
62
63
 
63
64
  <!-- leaflet-ui -->
64
65
  <script src="https://unpkg.com/leaflet@1.7.1/dist/leaflet.js"></script>
65
- <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>
66
67
 
67
68
  <!-- leaflet-elevation -->
68
69
  <link rel="stylesheet" href="https://unpkg.com/@raruto/leaflet-elevation/dist/leaflet-elevation.css" />
@@ -123,15 +124,15 @@ _For a working example see one of the following demos:_
123
124
  // Speed chart profile: true || "summary" || "disabled" || false
124
125
  speed: false,
125
126
 
127
+ // Altitude chart profile: true || "summary" || "disabled" || false
128
+ altitude: true,
129
+
126
130
  // Display time info: true || "summary" || false
127
- time: false,
131
+ time: true,
128
132
 
129
- // Display distance info: true || "summary"
133
+ // Display distance info: true || "summary" || false
130
134
  distance: true,
131
135
 
132
- // Display altitude info: true || "summary"
133
- altitude: true,
134
-
135
136
  // Summary track info style: "inline" || "multiline" || false
136
137
  summary: 'multiline',
137
138
 
@@ -186,6 +187,22 @@ _For a working example see one of the following demos:_
186
187
  </script>
187
188
  ```
188
189
 
190
+ ### Build Guide
191
+
192
+ For those wishing to try cloning this repository into a local development folder (eg. /var/www):
193
+
194
+ ```shell
195
+ git clone git@github.com:Raruto/leaflet-elevation.git
196
+ cd ./leaflet-elevation
197
+
198
+ npm i # install dependencies
199
+ npm run watch # auto-generate "dist" files
200
+ npm run build # generate "dist" files (once)
201
+ npm run test # test "spec" files (once)
202
+ ```
203
+
204
+ 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.
205
+
189
206
  ### FAQ
190
207
 
191
208
  <details>
@@ -247,6 +264,10 @@ var map = L.map('map', {
247
264
 
248
265
  _Related: [Leaflet-UI presets](https://github.com/raruto/leaflet-ui), [QGIS Integration](https://github.com/faunalia/trackprofile2web)_
249
266
 
267
+ ### Changelog
268
+
269
+ All notable changes to this project are documented in the [releases](https://github.com/Raruto/leaflet-elevation/releases) page.
270
+
250
271
  ---
251
272
 
252
273
  **Compatibile with:**
@@ -261,4 +282,4 @@ _Related: [Leaflet-UI presets](https://github.com/raruto/leaflet-ui), [QGIS Inte
261
282
 
262
283
  ---
263
284
 
264
- Check out [CONTRIBUTING.md](.github/CONTRIBUTING.md) file for more information on supporting the development of this library.
285
+ **License:** GPL-3.0+
@@ -97,7 +97,7 @@
97
97
  if (props) {
98
98
  for (const key of coordProps) {
99
99
  if (key in props) {
100
- point.meta[name] = (parser || parseInt).call(this, (isMulti ? props[key][isMulti] : props[key]), id);
100
+ point.meta[name] = (parser || parseNumeric).call(this, (isMulti ? props[key][isMulti] : props[key]), id);
101
101
  break;
102
102
  }
103
103
  }
@@ -108,7 +108,7 @@
108
108
  /**
109
109
  * Extract numeric property (id) from GeoJSON object
110
110
  */
111
- const parseInt = (property, id) => window.parseInt((typeof property === 'object' ? property[id] : property));
111
+ const parseNumeric = (property, id) => parseInt((typeof property === 'object' ? property[id] : property));
112
112
 
113
113
  /**
114
114
  * Extract datetime property (id) from GeoJSON object
@@ -136,10 +136,10 @@
136
136
  /**
137
137
  * TODO: use generators instead? (ie. "yield")
138
138
  */
139
- const iMax = (iVal, max) => (iVal > max ? iVal : max) || -Infinity;
140
- const iMin = (iVal, min) => (iVal < min ? iVal : min) || +Infinity;
141
- const iAvg = (iVal, avg) => (iVal + (avg || 0)) / 2.0;
142
- const iSum = (iVal, sum) => iVal + (sum || 0);
139
+ const iMax = (iVal, max = -Infinity) => (iVal > max ? iVal : max);
140
+ const iMin = (iVal, min = +Infinity) => (iVal < min ? iVal : min);
141
+ const iAvg = (iVal, avg = 0, idx = 1) => (iVal + avg * (idx - 1)) / idx;
142
+ const iSum = (iVal, sum = 0) => iVal + sum;
143
143
 
144
144
  /**
145
145
  * Alias for some leaflet core functions
@@ -171,7 +171,7 @@
171
171
  saveFile: saveFile,
172
172
  drawCanvas: drawCanvas,
173
173
  coordPropsToMeta: coordPropsToMeta,
174
- parseInt: parseInt,
174
+ parseNumeric: parseNumeric,
175
175
  parseDate: parseDate,
176
176
  addClass: addClass,
177
177
  removeClass: removeClass,
@@ -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 }),
@@ -516,17 +516,7 @@
516
516
 
517
517
  if (!this.eleDiv) this.eleDiv = container;
518
518
 
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)
519
+ this._loadModules(this.options.handlers).then(() => { // Inject here required modules (data handlers)
530
520
  this._initChart(container);
531
521
  this._initButton(container);
532
522
  this._initSummary(container);
@@ -866,14 +856,15 @@
866
856
  * Generate "svg" chart (DOM element).
867
857
  */
868
858
  _initChart: function(container) {
869
- let opts = this.options;
859
+ let opts = this.options;
860
+ let map = this._map;
870
861
 
871
862
  if (opts.detached) {
872
863
  let { offsetWidth, offsetHeight} = this.eleDiv;
873
864
  if (offsetWidth > 0) opts.width = offsetWidth;
874
865
  if (offsetHeight > 20) opts.height = offsetHeight - 20; // 20 = horizontal scrollbar size.
875
866
  } else {
876
- let { clientWidth } = this._map.getContainer();
867
+ let { clientWidth } = map.getContainer();
877
868
  opts._maxWidth = opts._maxWidth > opts.width ? opts._maxWidth : opts.width;
878
869
  this._container.style.maxWidth = opts._maxWidth + 'px';
879
870
  if (opts._maxWidth > clientWidth) opts.width = clientWidth - 30;
@@ -1013,22 +1004,16 @@
1013
1004
  // First map known classnames (eg. "Altitude" --> L.Control.Elevation.Altitude)
1014
1005
  handlers = handlers.map((h) => typeof h === 'string' && typeof Elevation[h] !== "undefined" ? Elevation[h] : h);
1015
1006
  // Then load optional classes and custom imports (eg. "Cadence" --> import('../src/handlers/cadence.js'))
1016
- return Promise.
1017
- all(
1018
- handlers
1019
- .filter(h => typeof h === 'string' || h instanceof Promise)
1020
- .map(file => file instanceof Promise ? file : this.import(this.__modulesFolder + file.toLowerCase() + '.js'))
1021
- )
1022
- .then((m) => {
1023
- each(m, (exported) => {
1024
- let fn = Object.keys(exported)[0];
1025
- if (fn && typeof Elevation[fn] === "undefined" ) {
1026
- handlers[fn] = Elevation[fn] = exported[fn];
1027
-
1028
- }
1029
- });
1030
- each(handlers, h => this._registerHandler(h));
1007
+ let modules = handlers.map(file => (typeof file === 'string' && this.import(this.__modulesFolder + file.toLowerCase() + '.js')) || (file instanceof Promise && file) || Promise.resolve());
1008
+ return Promise.all(modules).then((m) => {
1009
+ each(m, (exported, i) => {
1010
+ let fn = exported && Object.keys(exported)[0];
1011
+ if (fn) {
1012
+ handlers[i] = Elevation[fn] = (Elevation[fn] ?? exported[fn]);
1013
+ }
1031
1014
  });
1015
+ each(handlers, h => ["function", "object"].includes(typeof h) && this._registerHandler(h));
1016
+ });
1032
1017
  },
1033
1018
 
1034
1019
  /**
@@ -1317,7 +1302,7 @@
1317
1302
  if (props.stats) {
1318
1303
  for (const key in props.stats) {
1319
1304
  let sname = (props.statsName || attr) + (key != '' ? '_' : '');
1320
- this.track_info[sname + key] = props.stats[key].call(this, curr[attr], this.track_info[sname + key]);
1305
+ this.track_info[sname + key] = props.stats[key].call(this, curr[attr], this.track_info[sname + key], this._data.length);
1321
1306
  }
1322
1307
  }
1323
1308