@raruto/leaflet-elevation 2.2.8 → 2.3.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/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.1",
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
@@ -6,9 +6,6 @@ if (!L._ || !L.i18n) {
6
6
  L._ = L.i18n = (string, data) => string;
7
7
  }
8
8
 
9
- // Prevent CORS issues for relative locations (dynamic import)
10
- const baseURL = ((document.currentScript && document.currentScript.src) || (import.meta && import.meta.url)).split("/").slice(0,-1).join("/") + '/';
11
-
12
9
  export const Elevation = L.Control.Elevation = L.Control.extend({
13
10
 
14
11
  includes: L.Evented ? L.Evented.prototype : L.Mixin.Events,
@@ -22,11 +19,12 @@ export const Elevation = L.Control.Elevation = L.Control.extend({
22
19
  __LALMOSTOVER: 'https://unpkg.com/leaflet-almostover@1.0.1/src/leaflet.almostover.js',
23
20
  __LHOTLINE: '../libs/leaflet-hotline.min.js',
24
21
  __LDISTANCEM: '../libs/leaflet-distance-marker.min.js',
22
+ __LEDGESCALE: '../libs/leaflet-edgescale.min.js',
25
23
  __LCHART: '../src/components/chart.js',
26
24
  __LMARKER: '../src/components/marker.js',
27
25
  __LSUMMARY: '../src/components/summary.js',
28
26
  __modulesFolder: '../src/handlers/',
29
- __btnIcon: baseURL + '../images/elevation.svg',
27
+ __btnIcon: '../images/elevation.svg',
30
28
 
31
29
  /*
32
30
  * Add data to the diagram either from GPX or GeoJSON and update the axis domain and data
@@ -173,7 +171,10 @@ export const Elevation = L.Control.Elevation = L.Control.extend({
173
171
  */
174
172
  initialize: function(opts) {
175
173
 
176
- opts = L.setOptions(this, opts);
174
+ // opts = L.setOptions(this, opts);
175
+
176
+ // Fixes: https://github.com/Raruto/leaflet-elevation/pull/240
177
+ opts = L.setOptions(this, L.extend({}, structuredClone(Options), opts)); // "deep copy" nested objects (multiple charts)
177
178
 
178
179
  this._data = [];
179
180
  this._layers = L.featureGroup();
@@ -218,10 +219,10 @@ export const Elevation = L.Control.Elevation = L.Control.extend({
218
219
  case this.__LGEOMUTIL: condition = typeof L.GeometryUtil !== 'object'; break;
219
220
  case this.__LALMOSTOVER: condition = typeof L.Handler.AlmostOver !== 'function'; break;
220
221
  case this.__LDISTANCEM: condition = typeof L.DistanceMarkers !== 'function'; break;
222
+ case this.__LEDGESCALE: condition = typeof L.Control.EdgeScale !== 'function'; break;
221
223
  case this.__LHOTLINE: condition = typeof L.Hotline !== 'function'; break;
222
224
  }
223
- src = (src.startsWith('../') || src.startsWith('./') ? baseURL : '') + src;
224
- return condition !== false ? import(src) : Promise.resolve();
225
+ return condition !== false ? import(_.resolveURL(src, this.options.srcFolder)) : Promise.resolve();
225
226
  },
226
227
 
227
228
  /**
@@ -420,6 +421,16 @@ export const Elevation = L.Control.Elevation = L.Control.extend({
420
421
  return this.options.distanceMarkers ? Promise.all([this.import(this.__LGEOMUTIL), this.import(this.__LDISTANCEM)]) : Promise.resolve();
421
422
  },
422
423
 
424
+ /**
425
+ * Initialize "L.Control.EdgeScale" integration
426
+ */
427
+ _initEdgeScale: function(map) {
428
+ return this.options.edgeScale ? Promise.all([this.import(this.__LEDGESCALE)])
429
+ .then(() => {
430
+ map.edgeScaleControl = map.edgeScaleControl || L.control.edgeScale('boolean' !== typeof this.options.edgeScale ? this.options.edgeScale : {}).addTo(map);
431
+ }) : Promise.resolve();
432
+ },
433
+
423
434
  _initHotLine: function(layer) {
424
435
  let prop = typeof this.options.hotline == 'string' ? this.options.hotline : 'elevation';
425
436
  return this.options.hotline ? this.import(this.__LHOTLINE)
@@ -465,6 +476,7 @@ export const Elevation = L.Control.Elevation = L.Control.extend({
465
476
  this._initHotLine(layer),
466
477
  this._initAlmostOverHandler(map, layer),
467
478
  this._initDistanceMarkers(),
479
+ this._initEdgeScale(map),
468
480
  ]).then(() => {
469
481
  if (this.options.polyline) {
470
482
  layer.addTo(map);
@@ -700,7 +712,7 @@ export const Elevation = L.Control.Elevation = L.Control.extend({
700
712
  _.on(link, 'click', L.DomEvent.stop);
701
713
  _.on(link, 'click', this._toggle, this);
702
714
  _.on(link, 'focus', this._toggle, this);
703
- fetch(this.__btnIcon).then(r => r.ok && r.text().then(img => link.innerHTML = img));
715
+ fetch(_.resolveURL(this.__btnIcon, this.options.srcFolder)).then(r => r.ok && r.text().then(img => link.innerHTML = img));
704
716
  }
705
717
  },
706
718
 
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,
@@ -81,4 +82,7 @@ export var Options = {
81
82
  interpolation: "curveLinear",
82
83
  yAxisMax: undefined,
83
84
  yAxisMin: undefined,
85
+
86
+ // Prevent CORS issues for relative locations (dynamic import)
87
+ srcFolder: ((document.currentScript && document.currentScript.src) || (import.meta && import.meta.url)).split("/").slice(0,-1).join("/") + '/',
84
88
  };
package/src/utils.js CHANGED
@@ -16,6 +16,10 @@ const MIN = SEC * 60;
16
16
  const HOUR = MIN * 60;
17
17
  const DAY = HOUR * 24;
18
18
 
19
+ export function resolveURL(src, baseUrl) {
20
+ return (new URL(src, (src.startsWith('../') || src.startsWith('./')) ? baseUrl : undefined)).toString()
21
+ };
22
+
19
23
  /**
20
24
  * Convert a time (millis) to a human readable duration string (%Dd %H:%M'%S")
21
25
  */
@@ -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();