@raruto/leaflet-elevation 2.1.0 → 2.1.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 +22 -1
- package/dist/leaflet-elevation.js +22 -25
- package/dist/leaflet-elevation.js.map +1 -1
- package/dist/leaflet-elevation.min.js +1 -1
- package/dist/leaflet-elevation.min.js.map +1 -1
- package/package.json +8 -3
- package/spec/index.js +2 -0
- package/spec/index.min.js +1 -0
- package/spec/mock.js +26 -0
- package/spec/mock.min.js +1 -0
- package/spec/utils.test.js +41 -0
- package/spec/utils.test.min.js +1 -0
- package/src/components/d3.js +1 -1
- package/src/control.js +15 -18
- package/src/handlers/heart.js +52 -52
- package/src/utils.js +6 -6
package/README.md
CHANGED
|
@@ -23,6 +23,7 @@ _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
29
|
- [using .gpx extensions (cadence + heart)](https://raruto.github.io/leaflet-elevation/examples/leaflet-elevation_extended-ui.html)
|
|
@@ -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 dev # 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
|
-
|
|
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 ||
|
|
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
|
|
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)
|
|
140
|
-
const iMin = (iVal, min) => (iVal < min ? iVal : min)
|
|
141
|
-
const iAvg = (iVal, avg) => (iVal +
|
|
142
|
-
const iSum = (iVal, sum) => iVal +
|
|
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
|
-
|
|
174
|
+
parseNumeric: parseNumeric,
|
|
175
175
|
parseDate: parseDate,
|
|
176
176
|
addClass: addClass,
|
|
177
177
|
removeClass: removeClass,
|
|
@@ -866,14 +866,15 @@
|
|
|
866
866
|
* Generate "svg" chart (DOM element).
|
|
867
867
|
*/
|
|
868
868
|
_initChart: function(container) {
|
|
869
|
-
let opts
|
|
869
|
+
let opts = this.options;
|
|
870
|
+
let map = this._map;
|
|
870
871
|
|
|
871
872
|
if (opts.detached) {
|
|
872
873
|
let { offsetWidth, offsetHeight} = this.eleDiv;
|
|
873
874
|
if (offsetWidth > 0) opts.width = offsetWidth;
|
|
874
875
|
if (offsetHeight > 20) opts.height = offsetHeight - 20; // 20 = horizontal scrollbar size.
|
|
875
876
|
} else {
|
|
876
|
-
let { clientWidth } =
|
|
877
|
+
let { clientWidth } = map.getContainer();
|
|
877
878
|
opts._maxWidth = opts._maxWidth > opts.width ? opts._maxWidth : opts.width;
|
|
878
879
|
this._container.style.maxWidth = opts._maxWidth + 'px';
|
|
879
880
|
if (opts._maxWidth > clientWidth) opts.width = clientWidth - 30;
|
|
@@ -1013,22 +1014,18 @@
|
|
|
1013
1014
|
// First map known classnames (eg. "Altitude" --> L.Control.Elevation.Altitude)
|
|
1014
1015
|
handlers = handlers.map((h) => typeof h === 'string' && typeof Elevation[h] !== "undefined" ? Elevation[h] : h);
|
|
1015
1016
|
// Then load optional classes and custom imports (eg. "Cadence" --> import('../src/handlers/cadence.js'))
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
if (fn && typeof Elevation[fn] === "undefined" ) {
|
|
1026
|
-
handlers[fn] = Elevation[fn] = exported[fn];
|
|
1027
|
-
|
|
1028
|
-
}
|
|
1029
|
-
});
|
|
1030
|
-
each(handlers, h => this._registerHandler(h));
|
|
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'));
|
|
1020
|
+
return Promise.all(modules).then((m) => {
|
|
1021
|
+
each(m, (exported) => {
|
|
1022
|
+
let fn = Object.keys(exported)[0];
|
|
1023
|
+
if (fn) {
|
|
1024
|
+
handlers[fn] = Elevation[fn] = (Elevation[fn] ?? exported[fn]);
|
|
1025
|
+
}
|
|
1031
1026
|
});
|
|
1027
|
+
each(handlers, h => ["function", "object"].includes(typeof h) && this._registerHandler(h));
|
|
1028
|
+
});
|
|
1032
1029
|
},
|
|
1033
1030
|
|
|
1034
1031
|
/**
|
|
@@ -1317,7 +1314,7 @@
|
|
|
1317
1314
|
if (props.stats) {
|
|
1318
1315
|
for (const key in props.stats) {
|
|
1319
1316
|
let sname = (props.statsName || attr) + (key != '' ? '_' : '');
|
|
1320
|
-
this.track_info[sname + key] = props.stats[key].call(this, curr[attr], this.track_info[sname + key]);
|
|
1317
|
+
this.track_info[sname + key] = props.stats[key].call(this, curr[attr], this.track_info[sname + key], index);
|
|
1321
1318
|
}
|
|
1322
1319
|
}
|
|
1323
1320
|
|