@raruto/leaflet-elevation 2.2.1 → 2.2.4

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,6 +1,6 @@
1
1
  {
2
2
  "name": "@raruto/leaflet-elevation",
3
- "version": "2.2.1",
3
+ "version": "2.2.4",
4
4
  "description": "A Leaflet plugin that allows to add elevation profiles using d3js",
5
5
  "type": "module",
6
6
  "main": "dist/leaflet-elevation.min.js",
package/src/control.js CHANGED
@@ -6,6 +6,9 @@ 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
+
9
12
  export const Elevation = L.Control.Elevation = L.Control.extend({
10
13
 
11
14
  includes: L.Evented ? L.Evented.prototype : L.Mixin.Events,
@@ -23,6 +26,7 @@ export const Elevation = L.Control.Elevation = L.Control.extend({
23
26
  __LMARKER: '../src/components/marker.js',
24
27
  __LSUMMARY: '../src/components/summary.js',
25
28
  __modulesFolder: '../src/handlers/',
29
+ __btnIcon: '../images/elevation.svg',
26
30
 
27
31
  /*
28
32
  * Add data to the diagram either from GPX or GeoJSON and update the axis domain and data
@@ -30,10 +34,14 @@ export const Elevation = L.Control.Elevation = L.Control.extend({
30
34
  addData: function(d, layer) {
31
35
  this.import(this.__D3)
32
36
  .then(() => {
33
- layer = layer ?? (d.on && d);
34
- this._addData(d);
35
- this._addLayer(layer);
36
- this._fireEvt("eledata_added", { data: d, layer: layer, track_info: this.track_info });
37
+ if (this._modulesLoaded) {
38
+ layer = layer ?? (d.on && d);
39
+ this._addData(d);
40
+ this._addLayer(layer);
41
+ this._fireEvt("eledata_added", { data: d, layer: layer, track_info: this.track_info });
42
+ } else {
43
+ this.once('modules_loaded', () => this.addData(d,layer));
44
+ }
37
45
  });
38
46
  },
39
47
 
@@ -210,7 +218,9 @@ export const Elevation = L.Control.Elevation = L.Control.extend({
210
218
  case this.__LGEOMUTIL: condition = typeof L.GeometryUtil !== 'object'; break;
211
219
  case this.__LALMOSTOVER: condition = typeof L.Handler.AlmostOver !== 'function'; break;
212
220
  case this.__LDISTANCEM: condition = typeof L.DistanceMarkers !== 'function'; break;
221
+ case this.__LHOTLINE: condition = typeof L.Hotline !== 'function'; break;
213
222
  }
223
+ src = (src.startsWith('../') || src.startsWith('./') ? baseURL : '') + src;
214
224
  return condition !== false ? import(src) : Promise.resolve();
215
225
  },
216
226
 
@@ -238,6 +248,8 @@ export const Elevation = L.Control.Elevation = L.Control.extend({
238
248
  this._initSummary(container);
239
249
  this._initMarker(map);
240
250
  this._initLayer(map);
251
+ this._modulesLoaded = true;
252
+ this.fire('modules_loaded');
241
253
  });
242
254
 
243
255
  this.fire('add');
@@ -306,7 +318,7 @@ export const Elevation = L.Control.Elevation = L.Control.extend({
306
318
  if (geom) {
307
319
  switch (geom.type) {
308
320
  case 'LineString': return this._addGeoJSONData(geom.coordinates, d.properties);
309
- case 'MultiLineString': return _.each(geom.coordinates, (coords, i) => this._addGeoJSONData(coords, d.properties, i));
321
+ case 'MultiLineString': return _.each(geom.coordinates, (coords, i) => this._addGeoJSONData(coords, d.properties, i));
310
322
  case 'Point':
311
323
  default: return console.warn('Unsopperted GeoJSON feature geometry type:' + geom.type);
312
324
  }
@@ -687,6 +699,7 @@ export const Elevation = L.Control.Elevation = L.Control.extend({
687
699
  _.on(link, 'click', L.DomEvent.stop);
688
700
  _.on(link, 'click', this._toggle, this);
689
701
  _.on(link, 'focus', this._toggle, this);
702
+ fetch(this.__btnIcon).then(r => r.ok && r.text().then(img => link.innerHTML = img));
690
703
  }
691
704
  },
692
705
 
package/src/index.css CHANGED
@@ -146,7 +146,6 @@
146
146
  }
147
147
 
148
148
  .elevation-toggle-icon {
149
- background: var(--ele-toggle-bg, var(--ele-icon, url(../images/elevation-lime.svg)) no-repeat center center);
150
149
  background-color: #fff;
151
150
  right: 5px;
152
151
  top: 5px;
@@ -246,7 +245,7 @@
246
245
 
247
246
  .elevation-expanded {
248
247
  --ele-close-btn: inline-block;
249
- --ele-toggle-bg: transparent;
248
+ --ele-toggle-bg: none;
250
249
  --ele-toggle-pos: absolute;
251
250
  --ele-toggle-size: 20px;
252
251
  }
@@ -270,8 +269,8 @@
270
269
  --ele-area: #9CC222;
271
270
  --ele-grid: #CCC;
272
271
  --ele-brush: rgba(99, 126, 11, 0.4);
273
- --ele-icon: url(../images/elevation-lime.svg);
274
272
  --ele-poly: #566B13;
273
+ --ele-line: #70ab00;
275
274
  }
276
275
 
277
276
  /* STEELBLUE THEME //////////////////////////////////////////////// */
@@ -279,7 +278,7 @@
279
278
  --ele-axis: #0D1821;
280
279
  --ele-area: #4682B4;
281
280
  --ele-brush: rgba(23, 74, 117, 0.4);
282
- --ele-icon: url(../images/elevation-steelblue.svg);
281
+ --ele-line: #174A75;
283
282
  }
284
283
 
285
284
  /* PURPLE THEME /////////////////////////////////////////////////// */
@@ -287,7 +286,7 @@
287
286
  --ele-bg: rgba(115, 44, 123, 0.2);
288
287
  --ele-area: #732C7B;
289
288
  --ele-brush: rgba(74, 14, 80, 0.4);
290
- --ele-icon: url(../images/elevation-purple.svg);
289
+ --ele-line: #732c7b;
291
290
  }
292
291
 
293
292
  /* YELLOW THEME /////////////////////////////////////////////////// */
@@ -312,6 +311,7 @@
312
311
  --ele-alpha: 0.45;
313
312
  --ele-stroke: #4682B4;
314
313
  --ele-circle: #fff;
314
+ --ele-line: #000;
315
315
  }
316
316
 
317
317
  .elevation-detached.lightblue-theme .area {
@@ -1 +0,0 @@
1
- <svg xmlns="http://www.w3.org/2000/svg" width="26" height="26" viewBox="0 0 26 26"><defs/><path fill="#addb55" fill-opacity=".8" d="M23.1 20.8l-4.2-8-3.9-.2-2.7 1.8-2.4-5.5-5.2 6.2v5.7" opacity=".9"/><path fill="none" stroke="#70ab00" stroke-width="1.5" d="M4.7 14.8h1.1l4.3-6.2 2.5 5.6 2.5-2.3 3.7.2 4 8.3v.4"/><path fill="none" stroke="#737373" stroke-linecap="square" d="M3.4 5v19.8M24.7 22.4H.9"/></svg>
@@ -1 +0,0 @@
1
- <svg xmlns="http://www.w3.org/2000/svg" width="26" height="26" viewBox="0 0 26 26"><defs/><path fill="#b659c1" fill-opacity=".8" d="M23.1 20.8l-4.2-8-3.9-.2-2.7 1.8-2.4-5.5-5.2 6.2v5.7" opacity=".9"/><path fill="none" stroke="#732c7b" stroke-width="1.5" d="M4.7 14.8h1.1l4.3-6.2 2.5 5.6 2.5-2.3 3.7.2 4 8.3v.4"/><path fill="none" stroke="#737373" stroke-linecap="square" d="M3.4 5v19.8M24.7 22.4H.9"/></svg>
@@ -1 +0,0 @@
1
- <svg xmlns="http://www.w3.org/2000/svg" width="26" height="26" viewBox="0 0 26 26"><defs/><path fill="#4682b4" fill-opacity=".8" d="M23.1 20.8l-4.2-8-3.9-.2-2.7 1.8-2.4-5.5-5.2 6.2v5.7" opacity=".9"/><path fill="none" stroke="#174a75" stroke-width="1.5" d="M4.7 14.8h1.1l4.3-6.2 2.5 5.6 2.5-2.3 3.7.2 4 8.3v.4"/><path fill="none" stroke="#737373" stroke-linecap="square" d="M3.4 5v19.8M24.7 22.4H.9"/></svg>