@raruto/leaflet-elevation 2.3.2 → 2.3.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/src/control.js CHANGED
@@ -29,7 +29,7 @@ export const Elevation = L.Control.Elevation = L.Control.extend({
29
29
  /*
30
30
  * Add data to the diagram either from GPX or GeoJSON and update the axis domain and data
31
31
  */
32
- addData: function(d, layer) {
32
+ addData(d, layer) {
33
33
  this.import(this.__D3)
34
34
  .then(() => {
35
35
  if (this._modulesLoaded) {
@@ -46,7 +46,7 @@ export const Elevation = L.Control.Elevation = L.Control.extend({
46
46
  /**
47
47
  * Adds the control to the given map.
48
48
  */
49
- addTo: function(map) {
49
+ addTo(map) {
50
50
  if (this.options.detached) {
51
51
  let parent = _.select(this.options.elevationDiv);
52
52
  let eleDiv = this.onAdd(map);
@@ -60,12 +60,13 @@ export const Elevation = L.Control.Elevation = L.Control.extend({
60
60
  /*
61
61
  * Reset data and display
62
62
  */
63
- clear: function() {
63
+ clear() {
64
64
  if (this._marker) this._marker.remove();
65
65
  if (this._chart) this._clearChart();
66
66
  if (this._layers) this._clearLayers(this._layers);
67
67
  if (this._markers) this._clearLayers(this._markers);
68
68
  if (this._circleMarkers) this._circleMarkers.remove();
69
+ if (this._hotline) this._hotline.eachLayer(l => l.options.renderer.remove()); // hotfix for: https://github.com/Raruto/leaflet-elevation/issues/233
69
70
  if (this._hotline) this._clearLayers(this._hotline);
70
71
 
71
72
  this._data = [];
@@ -76,7 +77,7 @@ export const Elevation = L.Control.Elevation = L.Control.extend({
76
77
  this._updateChart();
77
78
  },
78
79
 
79
- _clearChart: function() {
80
+ _clearChart() {
80
81
  if (this._events && this._events.elechart_updated) {
81
82
  this._events.elechart_updated.forEach(({fn, ctx}) => this.off('elechart_updated', fn, ctx));
82
83
  }
@@ -86,7 +87,7 @@ export const Elevation = L.Control.Elevation = L.Control.extend({
86
87
  }
87
88
  },
88
89
 
89
- _clearLayers: function(l) {
90
+ _clearLayers(l) {
90
91
  l = l || this._layers;
91
92
  if (l && l.eachLayer) {
92
93
  l.eachLayer(f => f.remove())
@@ -113,7 +114,7 @@ export const Elevation = L.Control.Elevation = L.Control.extend({
113
114
  /**
114
115
  * Disable chart brushing.
115
116
  */
116
- disableBrush: function() {
117
+ disableBrush() {
117
118
  this._chart._brushEnabled = false;
118
119
  this._resetDrag();
119
120
  },
@@ -121,14 +122,14 @@ export const Elevation = L.Control.Elevation = L.Control.extend({
121
122
  /**
122
123
  * Enable chart brushing.
123
124
  */
124
- enableBrush: function() {
125
+ enableBrush() {
125
126
  this._chart._brushEnabled = true;
126
127
  },
127
128
 
128
129
  /**
129
130
  * Disable chart zooming.
130
131
  */
131
- disableZoom: function() {
132
+ disableZoom() {
132
133
  this._chart._zoomEnabled = false;
133
134
  this._chart._resetZoom();
134
135
  },
@@ -136,40 +137,40 @@ export const Elevation = L.Control.Elevation = L.Control.extend({
136
137
  /**
137
138
  * Enable chart zooming.
138
139
  */
139
- enableZoom: function() {
140
+ enableZoom() {
140
141
  this._chart._zoomEnabled = true;
141
142
  },
142
143
 
143
144
  /**
144
145
  * Sets a map view that contains the given geographical bounds.
145
146
  */
146
- fitBounds: function(bounds) {
147
+ fitBounds(bounds) {
147
148
  bounds = bounds || this.getBounds();
148
149
  if (this._map && bounds.isValid()) this._map.fitBounds(bounds);
149
150
  },
150
151
 
151
- getBounds: function(data) {
152
+ getBounds(data) {
152
153
  return L.latLngBounds((data || this._data).map((d) => d.latlng));
153
154
  },
154
155
 
155
156
  /**
156
157
  * Get default zoom level (followMarker: true).
157
158
  */
158
- getZFollow: function() {
159
+ getZFollow() {
159
160
  return this.options.zFollow;
160
161
  },
161
162
 
162
163
  /**
163
164
  * Hide current elevation chart profile.
164
165
  */
165
- hide: function() {
166
+ hide() {
166
167
  _.style(this._container, "display", "none");
167
168
  },
168
169
 
169
170
  /**
170
171
  * Initialize chart control "options" and "container".
171
172
  */
172
- initialize: function(opts) {
173
+ initialize(opts) {
173
174
 
174
175
  // opts = L.setOptions(this, opts);
175
176
 
@@ -212,7 +213,7 @@ export const Elevation = L.Control.Elevation = L.Control.extend({
212
213
  /**
213
214
  * Javascript scripts downloader (lazy loader)
214
215
  */
215
- import: function(src, condition) {
216
+ import(src, condition) {
216
217
  switch(src) {
217
218
  case this.__D3: condition = typeof d3 !== 'object'; break;
218
219
  case this.__TOGEOJSON: condition = typeof toGeoJSON !== 'object'; break;
@@ -228,7 +229,7 @@ export const Elevation = L.Control.Elevation = L.Control.extend({
228
229
  /**
229
230
  * Load elevation data (GPX, GeoJSON, KML or TCX).
230
231
  */
231
- load: function(data) {
232
+ load(data) {
232
233
  this._parseFromString(data).then( geojson => geojson ? this._loadLayer(geojson) : this._loadFile(data));
233
234
  },
234
235
 
@@ -236,7 +237,7 @@ export const Elevation = L.Control.Elevation = L.Control.extend({
236
237
  * Create container DOM element and related event listeners.
237
238
  * Called on control.addTo(map).
238
239
  */
239
- onAdd: function(map) {
240
+ onAdd(map) {
240
241
  this._map = map;
241
242
 
242
243
  let container = this._container = _.create("div", "elevation-control " + this.options.theme + " " + (this.options.detached ? 'elevation-detached' : 'leaflet-control'), this.options.detached ? { id: 'elevation-' + _.randomId() } : {});
@@ -262,7 +263,7 @@ export const Elevation = L.Control.Elevation = L.Control.extend({
262
263
  * Clean up control code and related event listeners.
263
264
  * Called on control.remove().
264
265
  */
265
- onRemove: function(map) {
266
+ onRemove(map) {
266
267
  this._container = null;
267
268
 
268
269
  map
@@ -285,28 +286,28 @@ export const Elevation = L.Control.Elevation = L.Control.extend({
285
286
  /**
286
287
  * Redraws the chart control. Sometimes useful after screen resize.
287
288
  */
288
- redraw: function() {
289
+ redraw() {
289
290
  this._resizeChart();
290
291
  },
291
292
 
292
293
  /**
293
294
  * Set default zoom level (followMarker: true).
294
295
  */
295
- setZFollow: function(zoom) {
296
+ setZFollow(zoom) {
296
297
  this.options.zFollow = zoom;
297
298
  },
298
299
 
299
300
  /**
300
301
  * Hide current elevation chart profile.
301
302
  */
302
- show: function() {
303
+ show() {
303
304
  _.style(this._container, "display", "block");
304
305
  },
305
306
 
306
307
  /*
307
308
  * Parsing data either from GPX or GeoJSON and update the diagram data
308
309
  */
309
- _addData: function(d) {
310
+ _addData(d) {
310
311
  if (!d) {
311
312
  return;
312
313
  }
@@ -336,7 +337,7 @@ export const Elevation = L.Control.Elevation = L.Control.extend({
336
337
  /*
337
338
  * Parsing of GeoJSON data lines and their elevation in z-coordinate
338
339
  */
339
- _addGeoJSONData: function(coords, properties, nestingLevel) {
340
+ _addGeoJSONData(coords, properties, nestingLevel) {
340
341
 
341
342
  // "coordinateProperties" property is generated inside "@tmcw/toGeoJSON"
342
343
  let props = (properties && properties.coordinateProperties) || properties;
@@ -367,7 +368,7 @@ export const Elevation = L.Control.Elevation = L.Control.extend({
367
368
  /*
368
369
  * Parse and push a single (x, y, z) point to current elevation profile.
369
370
  */
370
- _addPoint: function(x, y, z) {
371
+ _addPoint(x, y, z) {
371
372
  if (this.options.reverseCoords) {
372
373
  [x, y] = [y, x];
373
374
  }
@@ -382,7 +383,7 @@ export const Elevation = L.Control.Elevation = L.Control.extend({
382
383
  this.fire("eledata_updated", { index: this._data.length - 1 });
383
384
  },
384
385
 
385
- _addLayer: function(layer) {
386
+ _addLayer(layer) {
386
387
  if (layer) this._layers.addLayer(layer)
387
388
  // Postpone adding the distance markers (lazy: true)
388
389
  if (layer && this.options.distanceMarkers && this.options.distanceMarkers.lazy) {
@@ -391,7 +392,7 @@ export const Elevation = L.Control.Elevation = L.Control.extend({
391
392
  return layer;
392
393
  },
393
394
 
394
- _addMarker: function(marker) {
395
+ _addMarker(marker) {
395
396
  if (marker) this._markers.addLayer(marker)
396
397
  return marker;
397
398
  },
@@ -399,7 +400,7 @@ export const Elevation = L.Control.Elevation = L.Control.extend({
399
400
  /**
400
401
  * Initialize "L.AlmostOver" integration
401
402
  */
402
- _initAlmostOverHandler: function(map, layer) {
403
+ _initAlmostOverHandler(map, layer) {
403
404
  return (map && this.options.almostOver && !L.Browser.mobile) ? Promise.all([
404
405
  this.import(this.__LGEOMUTIL),
405
406
  this.import(this.__LALMOSTOVER)
@@ -408,8 +409,14 @@ export const Elevation = L.Control.Elevation = L.Control.extend({
408
409
  if (L.GeometryUtil && map.almostOver && map.almostOver.enabled()) {
409
410
  map.almostOver.addLayer(layer);
410
411
  map
411
- .on('almost:move', (e) => this._onMouseMoveLayer(e))
412
- .on('almost:out', (e) => this._onMouseOut(e));
412
+ .on('almost:move', this._onMouseMoveLayer, this)
413
+ .on('almost:out', this._onMouseOut, this);
414
+ this.once('eledata_clear', () => {
415
+ map.almostOver.removeLayer(layer);
416
+ map
417
+ .off('almost:move', this._onMouseMoveLayer, this)
418
+ .off('almost:out', this._onMouseOut, this);
419
+ })
413
420
  }
414
421
  }) : Promise.resolve();
415
422
  },
@@ -417,21 +424,21 @@ export const Elevation = L.Control.Elevation = L.Control.extend({
417
424
  /**
418
425
  * Initialize "L.DistanceMarkers" integration
419
426
  */
420
- _initDistanceMarkers: function() {
427
+ _initDistanceMarkers() {
421
428
  return this.options.distanceMarkers ? Promise.all([this.import(this.__LGEOMUTIL), this.import(this.__LDISTANCEM)]) : Promise.resolve();
422
429
  },
423
430
 
424
431
  /**
425
432
  * Initialize "L.Control.EdgeScale" integration
426
433
  */
427
- _initEdgeScale: function(map) {
434
+ _initEdgeScale(map) {
428
435
  return this.options.edgeScale ? Promise.all([this.import(this.__LEDGESCALE)])
429
436
  .then(() => {
430
437
  map.edgeScaleControl = map.edgeScaleControl || L.control.edgeScale('boolean' !== typeof this.options.edgeScale ? this.options.edgeScale : {}).addTo(map);
431
438
  }) : Promise.resolve();
432
439
  },
433
440
 
434
- _initHotLine: function(layer) {
441
+ _initHotLine(layer) {
435
442
  let prop = typeof this.options.hotline == 'string' ? this.options.hotline : 'elevation';
436
443
  return this.options.hotline ? this.import(this.__LHOTLINE)
437
444
  .then(() => {
@@ -465,7 +472,7 @@ export const Elevation = L.Control.Elevation = L.Control.extend({
465
472
  /**
466
473
  * Initialize "L.AlmostOver" and "L.DistanceMarkers"
467
474
  */
468
- _initMapIntegrations: function(layer) {
475
+ _initMapIntegrations(layer) {
469
476
  let map = this._map;
470
477
  if (map) {
471
478
  if (this._data.length) {
@@ -478,8 +485,8 @@ export const Elevation = L.Control.Elevation = L.Control.extend({
478
485
  this._initDistanceMarkers(),
479
486
  this._initEdgeScale(map),
480
487
  ]).then(() => {
481
- if (this.options.polyline) {
482
- layer.addTo(map);
488
+ if (this.options.polyline) {
489
+ this._layers.addLayer(layer.addTo(map)); // hotfix for: https://github.com/Raruto/leaflet-elevation/issues/233
483
490
  this._circleMarkers.addTo(map);
484
491
  }
485
492
  if (this.options.autofitBounds) {
@@ -495,7 +502,7 @@ export const Elevation = L.Control.Elevation = L.Control.extend({
495
502
  /*
496
503
  * Collapse current chart control.
497
504
  */
498
- _collapse: function() {
505
+ _collapse() {
499
506
  _.replaceClass(this._container, 'elevation-expanded', 'elevation-collapsed');
500
507
  if (this._map) this._map.invalidateSize();
501
508
  },
@@ -503,7 +510,7 @@ export const Elevation = L.Control.Elevation = L.Control.extend({
503
510
  /*
504
511
  * Expand current chart control.
505
512
  */
506
- _expand: function() {
513
+ _expand() {
507
514
  _.replaceClass(this._container, 'elevation-collapsed', 'elevation-expanded');
508
515
  if (this._map) this._map.invalidateSize();
509
516
  },
@@ -511,7 +518,7 @@ export const Elevation = L.Control.Elevation = L.Control.extend({
511
518
  /**
512
519
  * Add some basic colors to leaflet canvas renderer (preferCanvas: true).
513
520
  */
514
- _fixCanvasPaths: function() {
521
+ _fixCanvasPaths() {
515
522
  let oldProto = L.Canvas.prototype._fillStroke;
516
523
  let control = this;
517
524
 
@@ -519,7 +526,7 @@ export const Elevation = L.Control.Elevation = L.Control.extend({
519
526
  let color = _.Colors[theme] || {};
520
527
 
521
528
  L.Canvas.include({
522
- _fillStroke: function(ctx, layer) {
529
+ _fillStroke(ctx, layer) {
523
530
  if (control._layers.hasLayer(layer)) {
524
531
 
525
532
  let options = layer.options;
@@ -550,7 +557,7 @@ export const Elevation = L.Control.Elevation = L.Control.extend({
550
557
  *
551
558
  * @link https://github.com/Raruto/leaflet-elevation/issues/81#issuecomment-713477050
552
559
  */
553
- _fixTooltipSize: function() {
560
+ _fixTooltipSize() {
554
561
  this.on('elechart_init', () =>
555
562
  this.once('elechart_change elechart_hover', ({data, xCoord}) => {
556
563
  if (this._chartEnabled) {
@@ -565,21 +572,21 @@ export const Elevation = L.Control.Elevation = L.Control.extend({
565
572
  /*
566
573
  * Finds a data entry for the given LatLng
567
574
  */
568
- _findItemForLatLng: function(latlng) {
575
+ _findItemForLatLng(latlng) {
569
576
  return this._data[this._chart._findIndexForLatLng(latlng)];
570
577
  },
571
578
 
572
579
  /*
573
580
  * Finds a data entry for the given xDiagCoord
574
581
  */
575
- _findItemForX: function(x) {
582
+ _findItemForX(x) {
576
583
  return this._data[this._chart._findIndexForXCoord(x)];
577
584
  },
578
585
 
579
586
  /**
580
587
  * Fires an event of the specified type.
581
588
  */
582
- _fireEvt: function(type, data, propagate) {
589
+ _fireEvt(type, data, propagate) {
583
590
  if (this.fire) this.fire(type, data, propagate);
584
591
  if (this._map) this._map.fire(type, data, propagate);
585
592
  },
@@ -587,7 +594,7 @@ export const Elevation = L.Control.Elevation = L.Control.extend({
587
594
  /*
588
595
  * Hides the position/height indicator marker drawn onto the map
589
596
  */
590
- _hideMarker: function() {
597
+ _hideMarker() {
591
598
  if (this.options.autohideMarker) {
592
599
  this._marker.remove();
593
600
  }
@@ -596,7 +603,7 @@ export const Elevation = L.Control.Elevation = L.Control.extend({
596
603
  /**
597
604
  * Generate "svg" chart (DOM element).
598
605
  */
599
- _initChart: function(container) {
606
+ _initChart(container) {
600
607
  let opts = this.options;
601
608
  let map = this._map;
602
609
 
@@ -661,7 +668,7 @@ export const Elevation = L.Control.Elevation = L.Control.extend({
661
668
 
662
669
  },
663
670
 
664
- _initLayer: function() {
671
+ _initLayer() {
665
672
  this._layers
666
673
  .on('layeradd layerremove', ({layer, type}) => {
667
674
  let node = layer.getElement && layer.getElement();
@@ -671,7 +678,7 @@ export const Elevation = L.Control.Elevation = L.Control.extend({
671
678
  });
672
679
  },
673
680
 
674
- _initMarker: function(map) {
681
+ _initMarker(map) {
675
682
  let pane = map.getPane('elevationPane');
676
683
  if (!pane) {
677
684
  pane = this._pane = map.createPane('elevationPane', map.getPane('norotatePane') || map.getPane('mapPane'));
@@ -694,7 +701,7 @@ export const Elevation = L.Control.Elevation = L.Control.extend({
694
701
  /**
695
702
  * Inspired by L.Control.Layers
696
703
  */
697
- _initButton: function(container) {
704
+ _initButton(container) {
698
705
  L.DomEvent
699
706
  .disableClickPropagation(container)
700
707
  .disableScrollPropagation(container);
@@ -716,7 +723,7 @@ export const Elevation = L.Control.Elevation = L.Control.extend({
716
723
  }
717
724
  },
718
725
 
719
- _initSummary: function(container) {
726
+ _initSummary(container) {
720
727
  this.import(this.__LSUMMARY).then((m)=>{
721
728
  this._summary = new (m || Elevation).Summary({ summary: this.options.summary }, this);
722
729
 
@@ -729,7 +736,7 @@ export const Elevation = L.Control.Elevation = L.Control.extend({
729
736
  /**
730
737
  * Retrieve data from a remote url (HTTP).
731
738
  */
732
- _loadFile: function(url) {
739
+ _loadFile(url) {
733
740
  fetch(url)
734
741
  .then((response) => response.text())
735
742
  .then((data) => {
@@ -742,7 +749,7 @@ export const Elevation = L.Control.Elevation = L.Control.extend({
742
749
  /**
743
750
  * Dynamically import only required javascript modules (code splitting)
744
751
  */
745
- _loadModules: function(handlers) {
752
+ _loadModules(handlers) {
746
753
  // First map known classnames (eg. "Altitude" --> L.Control.Elevation.Altitude)
747
754
  handlers = handlers.map((h) => typeof h === 'string' && typeof Elevation[h] !== "undefined" ? Elevation[h] : h);
748
755
  // Then load optional classes and custom imports (eg. "Cadence" --> import('../src/handlers/cadence.js'))
@@ -761,7 +768,7 @@ export const Elevation = L.Control.Elevation = L.Control.extend({
761
768
  /**
762
769
  * Simple GeoJSON data loader (L.GeoJSON).
763
770
  */
764
- _loadLayer: function(geojson) {
771
+ _loadLayer(geojson) {
765
772
  let { polyline, theme, waypoints, wptIcons, wptLabels, distanceMarkers } = this.options;
766
773
  let style = L.extend({}, polyline);
767
774
 
@@ -809,14 +816,14 @@ export const Elevation = L.Control.Elevation = L.Control.extend({
809
816
  return layer;
810
817
  },
811
818
 
812
- _onDragEnd: function({ dragstart, dragend}) {
819
+ _onDragEnd({ dragstart, dragend}) {
813
820
  this._hideMarker();
814
821
  this.fitBounds(L.latLngBounds([dragstart.latlng, dragend.latlng]));
815
822
 
816
823
  this.fire("elechart_dragged");
817
824
  },
818
825
 
819
- _onKeyDown: function({key}) {
826
+ _onKeyDown({key}) {
820
827
  if(!this.options.detached && key === "Escape"){
821
828
  this._collapse()
822
829
  };
@@ -825,14 +832,14 @@ export const Elevation = L.Control.Elevation = L.Control.extend({
825
832
  /**
826
833
  * Trigger mouseenter event.
827
834
  */
828
- _onMouseEnter: function() {
835
+ _onMouseEnter() {
829
836
  this.fire('elechart_enter');
830
837
  },
831
838
 
832
839
  /*
833
840
  * Handles the moueseover the chart and displays distance and altitude level.
834
841
  */
835
- _onMouseMove: function({xCoord}) {
842
+ _onMouseMove({xCoord}) {
836
843
  if (this._chartEnabled && this._data.length) {
837
844
  let item = this._findItemForX(xCoord);
838
845
  if (item) {
@@ -854,7 +861,7 @@ export const Elevation = L.Control.Elevation = L.Control.extend({
854
861
  /*
855
862
  * Handles mouseover events of the data layers on the map.
856
863
  */
857
- _onMouseMoveLayer: function({latlng}) {
864
+ _onMouseMoveLayer({latlng}) {
858
865
  if (this._data.length) {
859
866
  let item = this._findItemForLatLng(latlng);
860
867
  if (item) {
@@ -872,7 +879,7 @@ export const Elevation = L.Control.Elevation = L.Control.extend({
872
879
  /*
873
880
  * Handles the moueseout over the chart.
874
881
  */
875
- _onMouseOut: function() {
882
+ _onMouseOut() {
876
883
  if (!this.options.detached) {
877
884
  this._hideMarker();
878
885
  this._chart._hideDiagramIndicator();
@@ -888,14 +895,14 @@ export const Elevation = L.Control.Elevation = L.Control.extend({
888
895
  /**
889
896
  * Handles the drag event over the ruler filter.
890
897
  */
891
- _onRulerFilter: function({coords}) {
898
+ _onRulerFilter({coords}) {
892
899
  this._updateMapSegments(coords);
893
900
  },
894
901
 
895
902
  /**
896
903
  * Toggle chart data on legend click
897
904
  */
898
- _onToggleChart: function({ name, enabled }) {
905
+ _onToggleChart({ name, enabled }) {
899
906
 
900
907
  this._chartEnabled = this._chart._hasActiveLayers();
901
908
 
@@ -915,7 +922,7 @@ export const Elevation = L.Control.Elevation = L.Control.extend({
915
922
  /**
916
923
  * Simple GeoJSON Parser
917
924
  */
918
- _parseFromGeoJSONString: function(data) {
925
+ _parseFromGeoJSONString(data) {
919
926
  try {
920
927
  return JSON.parse(data);
921
928
  } catch (e) { }
@@ -924,7 +931,7 @@ export const Elevation = L.Control.Elevation = L.Control.extend({
924
931
  /**
925
932
  * Attempt to parse raw response data (GeoJSON or XML > GeoJSON)
926
933
  */
927
- _parseFromString: function(data) {
934
+ _parseFromString(data) {
928
935
  return new Promise(resolve =>
929
936
  this.import(this.__TOGEOJSON).then(() => {
930
937
  let geojson;
@@ -944,7 +951,7 @@ export const Elevation = L.Control.Elevation = L.Control.extend({
944
951
  /**
945
952
  * Simple XML Parser (GPX, KML, TCX)
946
953
  */
947
- _parseFromXMLString: function(data) {
954
+ _parseFromXMLString(data) {
948
955
  if (data.indexOf("<") != 0) {
949
956
  throw 'Invalid XML';
950
957
  }
@@ -965,36 +972,38 @@ export const Elevation = L.Control.Elevation = L.Control.extend({
965
972
  /**
966
973
  * Add chart profile to diagram
967
974
  */
968
- _registerAreaPath: function(props) {
975
+ _registerAreaPath(props) {
969
976
  this.on("elechart_init", () => this._chart._registerAreaPath(props));
970
977
  },
971
978
 
972
979
  /**
973
980
  * Add chart grid to diagram
974
981
  */
975
- _registerAxisGrid: function(props) {
982
+ _registerAxisGrid(props) {
976
983
  this.on("elechart_axis", () => this._chart._registerAxisGrid(props));
977
984
  },
978
985
 
979
986
  /**
980
987
  * Add chart axis to diagram
981
988
  */
982
- _registerAxisScale: function(props) {
989
+ _registerAxisScale(props) {
983
990
  this.on("elechart_axis", () => this._chart._registerAxisScale(props));
984
991
  },
985
992
 
986
993
  /**
987
994
  * Add a point of interest over the diagram
988
995
  */
989
- _registerCheckPoint: function(props) {
990
- this.on("elechart_updated", () => this._chart._registerCheckPoint(props));
996
+ _registerCheckPoint(props) {
997
+ const cb = () => this._chart._registerCheckPoint(props);
998
+ this
999
+ .on("elechart_updated", cb)
1000
+ .once("eledata_clear", () => this.off("elechart_updated", cb));
991
1001
  },
992
1002
 
993
-
994
1003
  /**
995
1004
  * Base handler for iterative track statistics (dist, time, z, slope, speed, acceleration, ...)
996
1005
  */
997
- _registerDataAttribute: function(props) {
1006
+ _registerDataAttribute(props) {
998
1007
 
999
1008
  // parse of "coordinateProperties" for later usage
1000
1009
  if (props.coordPropsToMeta) {
@@ -1071,7 +1080,7 @@ export const Elevation = L.Control.Elevation = L.Control.extend({
1071
1080
  /**
1072
1081
  * Parse a module definition and attach related function listeners
1073
1082
  */
1074
- _registerHandler: function(props) {
1083
+ _registerHandler(props) {
1075
1084
 
1076
1085
  // eg. L.Control.Altitude
1077
1086
  if (typeof props === "function") {
@@ -1154,7 +1163,7 @@ export const Elevation = L.Control.Elevation = L.Control.extend({
1154
1163
  /**
1155
1164
  * Add chart or marker tooltip info
1156
1165
  */
1157
- _registerTooltip: function(props) {
1166
+ _registerTooltip(props) {
1158
1167
  props.chart && this.on("elechart_init", () => this._chart._registerTooltip(L.extend({}, props, { value: props.chart })));
1159
1168
  props.marker && this.on("elechart_marker", () => this._marker._registerTooltip(L.extend({}, props, { value: props.marker })));
1160
1169
  },
@@ -1162,14 +1171,14 @@ export const Elevation = L.Control.Elevation = L.Control.extend({
1162
1171
  /**
1163
1172
  * Add summary info to diagram
1164
1173
  */
1165
- _registerSummary: function(props) {
1174
+ _registerSummary(props) {
1166
1175
  this.on('elechart_summary', () => this._summary._registerSummary(props));
1167
1176
  },
1168
1177
 
1169
1178
  /*
1170
1179
  * Removes the drag rectangle and zoms back to the total extent of the data.
1171
1180
  */
1172
- _resetDrag: function() {
1181
+ _resetDrag() {
1173
1182
  this._chart._resetDrag();
1174
1183
  this._hideMarker();
1175
1184
  },
@@ -1177,7 +1186,7 @@ export const Elevation = L.Control.Elevation = L.Control.extend({
1177
1186
  /**
1178
1187
  * Resets drag, marker and bounds.
1179
1188
  */
1180
- _resetView: function() {
1189
+ _resetView() {
1181
1190
  if (this._map && this._map._isFullscreen) return;
1182
1191
  this._resetDrag();
1183
1192
  this._hideMarker();
@@ -1189,7 +1198,7 @@ export const Elevation = L.Control.Elevation = L.Control.extend({
1189
1198
  /**
1190
1199
  * Hacky way for handling chart resize. Deletes it and redraw chart.
1191
1200
  */
1192
- _resizeChart: function() {
1201
+ _resizeChart() {
1193
1202
  if (this._container && _.style(this._container, "display") != "none") {
1194
1203
  let opts = this.options;
1195
1204
  let newWidth = opts.detached ? (this.eleDiv || this._container).offsetWidth : _.clamp(opts._maxWidth, [0, this._map.getContainer().clientWidth - 30]);
@@ -1207,14 +1216,14 @@ export const Elevation = L.Control.Elevation = L.Control.extend({
1207
1216
  /**
1208
1217
  * Collapse or Expand chart control.
1209
1218
  */
1210
- _toggle: function() {
1219
+ _toggle() {
1211
1220
  _.hasClass(this._container, "elevation-expanded") ? this._collapse() : this._expand();
1212
1221
  },
1213
1222
 
1214
1223
  /**
1215
1224
  * Update map center and zoom (followMarker: true)
1216
1225
  */
1217
- _setMapView: function(item) {
1226
+ _setMapView(item) {
1218
1227
  if (this._map && this.options.followMarker) {
1219
1228
  let zoom = this._map.getZoom();
1220
1229
  let z = this.options.zFollow;
@@ -1229,7 +1238,7 @@ export const Elevation = L.Control.Elevation = L.Control.extend({
1229
1238
  /**
1230
1239
  * Calculates [x, y] domain and then update chart.
1231
1240
  */
1232
- _updateChart: function() {
1241
+ _updateChart() {
1233
1242
  if (this._chart && this._container) {
1234
1243
  this.fire("elechart_axis");
1235
1244
 
@@ -1245,7 +1254,7 @@ export const Elevation = L.Control.Elevation = L.Control.extend({
1245
1254
  /*
1246
1255
  * Update the position/height indicator marker drawn onto the map
1247
1256
  */
1248
- _updateMarker: function(item) {
1257
+ _updateMarker(item) {
1249
1258
  if (this._marker) {
1250
1259
  this._marker.update({
1251
1260
  map : this._map,
@@ -1259,7 +1268,7 @@ export const Elevation = L.Control.Elevation = L.Control.extend({
1259
1268
  /**
1260
1269
  * Fix marker rotation on rotated maps
1261
1270
  */
1262
- _rotateMarker: function() {
1271
+ _rotateMarker() {
1263
1272
  if (this._marker) {
1264
1273
  this._marker.update();
1265
1274
  }
@@ -1268,7 +1277,7 @@ export const Elevation = L.Control.Elevation = L.Control.extend({
1268
1277
  /**
1269
1278
  * Highlight track segments on the map.
1270
1279
  */
1271
- _updateMapSegments: function(coords) {
1280
+ _updateMapSegments(coords) {
1272
1281
  this._markedSegments.setLatLngs(coords || []);
1273
1282
  if (coords && this._map && !this._map.hasLayer(this._markedSegments)) {
1274
1283
  this._markedSegments.addTo(this._map);
@@ -1278,7 +1287,7 @@ export const Elevation = L.Control.Elevation = L.Control.extend({
1278
1287
  /**
1279
1288
  * Update chart summary.
1280
1289
  */
1281
- _updateSummary: function() {
1290
+ _updateSummary() {
1282
1291
  if (this._summary) {
1283
1292
  this._summary.reset();
1284
1293
  if (this.options.summary) {
@@ -1305,7 +1314,7 @@ export const Elevation = L.Control.Elevation = L.Control.extend({
1305
1314
  /**
1306
1315
  * Calculates chart width.
1307
1316
  */
1308
- _width: function() {
1317
+ _width() {
1309
1318
  if (this._chart) return this._chart._width();
1310
1319
  const { width, margins } = this.options;
1311
1320
  return width - margins.left - margins.right;
@@ -1314,7 +1323,7 @@ export const Elevation = L.Control.Elevation = L.Control.extend({
1314
1323
  /**
1315
1324
  * Calculates chart height.
1316
1325
  */
1317
- _height: function() {
1326
+ _height() {
1318
1327
  if (this._chart) return this._chart._height();
1319
1328
  const { height, margins } = this.options;
1320
1329
  return height - margins.top - margins.bottom;