@raruto/leaflet-elevation 2.2.8 → 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/package.json CHANGED
@@ -1,71 +1,74 @@
1
1
  {
2
- "name": "@raruto/leaflet-elevation",
3
- "version": "2.2.8",
4
- "description": "A Leaflet plugin that allows to add elevation profiles using d3js",
5
- "type": "module",
6
- "main": "dist/leaflet-elevation.min.js",
7
- "browser": "dist/leaflet-elevation.min.js",
8
- "module": "src/index.js",
9
- "scripts": {
10
- "test": "node spec/index.js",
11
- "build": "rollup -c build/rollup.config.js",
12
- "watch": "rollup -c build/rollup.config.js --watch",
13
- "dev": "npm run watch",
14
- "version": "npm run build && git add -A"
15
- },
16
- "repository": {
17
- "type": "git",
18
- "url": "https://github.com/Raruto/leaflet-elevation.git"
19
- },
20
- "keywords": [
21
- "leaflet",
22
- "d3js",
23
- "javascript",
24
- "elevation",
25
- "highchart",
26
- "kml",
27
- "altitude",
28
- "gpx",
29
- "gps-visualizer",
30
- "tcx"
31
- ],
32
- "author": {
33
- "name": "Felix “MrMufflon” Bache",
34
- "url": "https: //github.com/MrMufflon/Leaflet.Elevation"
35
- },
36
- "contributors": [
37
- {
38
- "name": "Raruto",
39
- "url": "https://github.com/Raruto/leaflet-elevation"
40
- },
41
- {
42
- "name": "Felix Bache",
43
- "web": "https://github.com/HostedDinner/Leaflet.Elevation"
44
- }
45
- ],
46
- "license": "GPL-3.0",
47
- "bugs": {
48
- "url": "https://github.com/Raruto/leaflet-elevation/issues"
49
- },
50
- "homepage": "https://github.com/Raruto/leaflet-elevation#readme",
51
- "devDependencies": {
52
- "jsdom": "^20.0.0",
53
- "leaflet": "^1.7.1",
54
- "postcss": "^8.4.16",
55
- "postcss-copy": "^7.1.0",
56
- "postcss-import": "^15.0.0",
57
- "rollup": "^2.79.0",
58
- "rollup-plugin-commonjs": "^10.1.0",
59
- "rollup-plugin-git-version": "^0.3.1",
60
- "rollup-plugin-node-resolve": "^5.2.0",
61
- "rollup-plugin-postcss": "^4.0.2",
62
- "rollup-plugin-terser": "^7.0.2",
63
- "uvu": "^0.5.6"
64
- },
65
- "peerDependencies": {
66
- "leaflet": "^1.7.0",
67
- "leaflet-i18n": "^0.3.1",
68
- "d3": "6.5.0",
69
- "@tmcw/togeojson": "4.6.0"
70
- }
2
+ "name": "@raruto/leaflet-elevation",
3
+ "version": "2.3.0",
4
+ "description": "A Leaflet plugin that allows to add elevation profiles using d3js",
5
+ "type": "module",
6
+ "main": "dist/leaflet-elevation.min.js",
7
+ "browser": "dist/leaflet-elevation.min.js",
8
+ "module": "src/index.js",
9
+ "scripts": {
10
+ "test": "uvu . ^(examples)?(src)?\\.*\\.spec\\.js$",
11
+ "build": "rollup -c build/rollup.config.js",
12
+ "watch": "rollup -c build/rollup.config.js --watch",
13
+ "dev": "npm-run-all --print-label --parallel serve watch",
14
+ "serve": "http-server",
15
+ "version": "npm run build && git add -A"
16
+ },
17
+ "repository": {
18
+ "type": "git",
19
+ "url": "https://github.com/Raruto/leaflet-elevation.git"
20
+ },
21
+ "keywords": [
22
+ "leaflet",
23
+ "d3js",
24
+ "javascript",
25
+ "elevation",
26
+ "highchart",
27
+ "kml",
28
+ "altitude",
29
+ "gpx",
30
+ "gps-visualizer",
31
+ "tcx"
32
+ ],
33
+ "author": {
34
+ "name": "Felix “MrMufflon” Bache",
35
+ "url": "https: //github.com/MrMufflon/Leaflet.Elevation"
36
+ },
37
+ "contributors": [
38
+ {
39
+ "name": "Raruto",
40
+ "url": "https://github.com/Raruto/leaflet-elevation"
41
+ },
42
+ {
43
+ "name": "Felix Bache",
44
+ "web": "https://github.com/HostedDinner/Leaflet.Elevation"
45
+ }
46
+ ],
47
+ "license": "GPL-3.0",
48
+ "bugs": {
49
+ "url": "https://github.com/Raruto/leaflet-elevation/issues"
50
+ },
51
+ "homepage": "https://github.com/Raruto/leaflet-elevation#readme",
52
+ "devDependencies": {
53
+ "@rollup/plugin-commonjs": "^24.1.0",
54
+ "@rollup/plugin-node-resolve": "^15.0.2",
55
+ "@rollup/plugin-terser": "^0.4.1",
56
+ "http-server": "^14.1.1",
57
+ "jsdom": "^20.0.0",
58
+ "leaflet": "^1.7.1",
59
+ "npm-run-all": "^4.1.5",
60
+ "playwright": "^1.32.3",
61
+ "postcss": "^8.4.22",
62
+ "postcss-copy": "^7.1.0",
63
+ "postcss-import": "^15.1.0",
64
+ "rollup": "^3.20.6",
65
+ "rollup-plugin-postcss": "^4.0.2",
66
+ "uvu": "^0.5.6"
67
+ },
68
+ "peerDependencies": {
69
+ "@tmcw/togeojson": "4.6.0",
70
+ "d3": "6.5.0",
71
+ "leaflet": "^1.7.0",
72
+ "leaflet-i18n": "^0.3.1"
73
+ }
71
74
  }
package/src/control.js CHANGED
@@ -22,6 +22,7 @@ export const Elevation = L.Control.Elevation = L.Control.extend({
22
22
  __LALMOSTOVER: 'https://unpkg.com/leaflet-almostover@1.0.1/src/leaflet.almostover.js',
23
23
  __LHOTLINE: '../libs/leaflet-hotline.min.js',
24
24
  __LDISTANCEM: '../libs/leaflet-distance-marker.min.js',
25
+ __LEDGESCALE: '../libs/leaflet-edgescale.min.js',
25
26
  __LCHART: '../src/components/chart.js',
26
27
  __LMARKER: '../src/components/marker.js',
27
28
  __LSUMMARY: '../src/components/summary.js',
@@ -173,7 +174,10 @@ export const Elevation = L.Control.Elevation = L.Control.extend({
173
174
  */
174
175
  initialize: function(opts) {
175
176
 
176
- opts = L.setOptions(this, opts);
177
+ // opts = L.setOptions(this, opts);
178
+
179
+ // Fixes: https://github.com/Raruto/leaflet-elevation/pull/240
180
+ opts = L.setOptions(this, L.extend({}, structuredClone(Options), opts)); // "deep copy" nested objects (multiple charts)
177
181
 
178
182
  this._data = [];
179
183
  this._layers = L.featureGroup();
@@ -218,6 +222,7 @@ export const Elevation = L.Control.Elevation = L.Control.extend({
218
222
  case this.__LGEOMUTIL: condition = typeof L.GeometryUtil !== 'object'; break;
219
223
  case this.__LALMOSTOVER: condition = typeof L.Handler.AlmostOver !== 'function'; break;
220
224
  case this.__LDISTANCEM: condition = typeof L.DistanceMarkers !== 'function'; break;
225
+ case this.__LEDGESCALE: condition = typeof L.Control.EdgeScale !== 'function'; break;
221
226
  case this.__LHOTLINE: condition = typeof L.Hotline !== 'function'; break;
222
227
  }
223
228
  src = (src.startsWith('../') || src.startsWith('./') ? baseURL : '') + src;
@@ -420,6 +425,16 @@ export const Elevation = L.Control.Elevation = L.Control.extend({
420
425
  return this.options.distanceMarkers ? Promise.all([this.import(this.__LGEOMUTIL), this.import(this.__LDISTANCEM)]) : Promise.resolve();
421
426
  },
422
427
 
428
+ /**
429
+ * Initialize "L.Control.EdgeScale" integration
430
+ */
431
+ _initEdgeScale: function(map) {
432
+ return this.options.edgeScale ? Promise.all([this.import(this.__LEDGESCALE)])
433
+ .then(() => {
434
+ map.edgeScaleControl = map.edgeScaleControl || L.control.edgeScale('boolean' !== typeof this.options.edgeScale ? this.options.edgeScale : {}).addTo(map);
435
+ }) : Promise.resolve();
436
+ },
437
+
423
438
  _initHotLine: function(layer) {
424
439
  let prop = typeof this.options.hotline == 'string' ? this.options.hotline : 'elevation';
425
440
  return this.options.hotline ? this.import(this.__LHOTLINE)
@@ -465,6 +480,7 @@ export const Elevation = L.Control.Elevation = L.Control.extend({
465
480
  this._initHotLine(layer),
466
481
  this._initAlmostOverHandler(map, layer),
467
482
  this._initDistanceMarkers(),
483
+ this._initEdgeScale(map),
468
484
  ]).then(() => {
469
485
  if (this.options.polyline) {
470
486
  layer.addTo(map);
package/src/options.js CHANGED
@@ -14,6 +14,7 @@ export var Options = {
14
14
  dragging: !L.Browser.mobile,
15
15
  downloadLink: 'link',
16
16
  elevationDiv: "#elevation-div",
17
+ edgeScale: { bar: true, icon: false, coords: false },
17
18
  followMarker: true,
18
19
  imperial: false,
19
20
  legend: true,
@@ -0,0 +1,50 @@
1
+ /**
2
+ * src/utils.js
3
+ */
4
+
5
+ import { suite } from 'uvu';
6
+ import * as assert from 'uvu/assert';
7
+ import '../test/setup/jsdom.js'
8
+ import { iAvg, iMin, iMax, iSum } from "../src/utils.js";
9
+
10
+ const toFixed = (n) => +n.toFixed(2);
11
+
12
+ const test = suite('src/utils.js');
13
+
14
+ test('iAvg()', () => {
15
+ let avg;
16
+ avg = iAvg(100, undefined, 1); assert.is(toFixed(avg), 100); // average for [100] is 100
17
+ avg = iAvg(100, avg, 2); assert.is(toFixed(avg), 100); // average for [100, 100] is 100
18
+ avg = iAvg(200, avg, 3); assert.is(toFixed(avg), 133.33); // average for [100, 100, 200] is 133.33
19
+ avg = iAvg(200, avg, 4); assert.is(toFixed(avg), 150); // average for [100, 100, 200, 200] is 150
20
+ avg = iAvg(NaN, avg, 5); assert.ok(isNaN(avg)); // average for [100, 100, 200, 200, NaN] is NaN
21
+ });
22
+
23
+ test('iMin()', () => {
24
+ let min;
25
+ min = iMin(100, undefined); assert.is(toFixed(min), 100); // min for [100] is 100
26
+ min = iMin(NaN, min); assert.is(toFixed(min), 100); // min for [100, NaN] is 100
27
+ min = iMin(0, min); assert.is(toFixed(min), 0); // min for [100, NaN, 0] is 100
28
+ min = iMin(-200, min); assert.is(toFixed(min), -200); // min for [100, NaN, 0, -200] is -200
29
+ min = iMin(200, min); assert.is(toFixed(min), -200); // min for [100, NaN, -100, -200, 200] is -200
30
+ });
31
+
32
+ test('iMax()', () => {
33
+ let max;
34
+ max = iMax(100, undefined); assert.is(toFixed(max), 100); // max for [100] is 100
35
+ max = iMax(NaN, max); assert.is(toFixed(max), 100); // max for [100, NaN] is 100
36
+ max = iMax(0, max); assert.is(toFixed(max), 100); // max for [100, NaN, 0] is 100
37
+ max = iMax(-200, max); assert.is(toFixed(max), 100); // max for [100, NaN, 0, -200] is 100
38
+ max = iMax(200, max); assert.is(toFixed(max), 200); // max for [100, NaN, -100, -200, 200] is 200
39
+ });
40
+
41
+ test('iSum()', () => {
42
+ let sum;
43
+ sum = iSum(10.25, undefined); assert.is(toFixed(sum), 10.25); // sum for [10.25] is 10.25
44
+ sum = iSum(0, sum); assert.is(toFixed(sum), 10.25); // sum for [10.25, 0] is 10.25
45
+ sum = iSum(-0.25, sum); assert.is(toFixed(sum), 10); // sum for [10.25, 0, -0.25] is 10
46
+ sum = iSum(-10, sum); assert.is(toFixed(sum), 0); // sum for [10.25, 0, -0.25, -10] is 0
47
+ sum = iSum(NaN, sum); assert.ok(isNaN(sum)); // sum for [10.25, 0, -0.25, -10, NaN] is NaN
48
+ });
49
+
50
+ test.run();