@raruto/leaflet-elevation 2.2.1 → 2.2.2

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.2",
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
@@ -30,10 +30,14 @@ export const Elevation = L.Control.Elevation = L.Control.extend({
30
30
  addData: function(d, layer) {
31
31
  this.import(this.__D3)
32
32
  .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 });
33
+ if (this._modulesLoaded) {
34
+ layer = layer ?? (d.on && d);
35
+ this._addData(d);
36
+ this._addLayer(layer);
37
+ this._fireEvt("eledata_added", { data: d, layer: layer, track_info: this.track_info });
38
+ } else {
39
+ this.once('modules_loaded', () => this.addData(d,layer));
40
+ }
37
41
  });
38
42
  },
39
43
 
@@ -238,6 +242,8 @@ export const Elevation = L.Control.Elevation = L.Control.extend({
238
242
  this._initSummary(container);
239
243
  this._initMarker(map);
240
244
  this._initLayer(map);
245
+ this._modulesLoaded = true;
246
+ this.fire('modules_loaded');
241
247
  });
242
248
 
243
249
  this.fire('add');
@@ -306,7 +312,7 @@ export const Elevation = L.Control.Elevation = L.Control.extend({
306
312
  if (geom) {
307
313
  switch (geom.type) {
308
314
  case 'LineString': return this._addGeoJSONData(geom.coordinates, d.properties);
309
- case 'MultiLineString': return _.each(geom.coordinates, (coords, i) => this._addGeoJSONData(coords, d.properties, i));
315
+ case 'MultiLineString': return _.each(geom.coordinates, (coords, i) => this._addGeoJSONData(coords, d.properties, i));
310
316
  case 'Point':
311
317
  default: return console.warn('Unsopperted GeoJSON feature geometry type:' + geom.type);
312
318
  }