@raruto/leaflet-elevation 1.8.3 → 1.8.6

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.
@@ -45,62 +45,6 @@
45
45
  };
46
46
  }, window);
47
47
 
48
- function _typeof(obj) {
49
- "@babel/helpers - typeof";
50
-
51
- if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") {
52
- _typeof = function (obj) {
53
- return typeof obj;
54
- };
55
- } else {
56
- _typeof = function (obj) {
57
- return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
58
- };
59
- }
60
-
61
- return _typeof(obj);
62
- }
63
-
64
- function _defineProperty(obj, key, value) {
65
- if (key in obj) {
66
- Object.defineProperty(obj, key, {
67
- value: value,
68
- enumerable: true,
69
- configurable: true,
70
- writable: true
71
- });
72
- } else {
73
- obj[key] = value;
74
- }
75
-
76
- return obj;
77
- }
78
-
79
- /**
80
- * Recursive deep merge objects.
81
- * Alternative to L.Util.setOptions(this, options).
82
- */
83
- function deepMerge(target) {
84
- for (var _len = arguments.length, sources = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
85
- sources[_key - 1] = arguments[_key];
86
- }
87
-
88
- if (!sources.length) return target;
89
- var source = sources.shift();
90
-
91
- if (isObject(target) && isObject(source)) {
92
- for (var key in source) {
93
- if (isObject(source[key])) {
94
- if (!target[key]) Object.assign(target, _defineProperty({}, key, {}));
95
- deepMerge(target[key], source[key]);
96
- } else {
97
- Object.assign(target, _defineProperty({}, key, source[key]));
98
- }
99
- }
100
- }
101
-
102
- return deepMerge.apply(void 0, [target].concat(sources));
103
- }
104
48
  var SEC = 1000;
105
49
  var MIN = SEC * 60;
106
50
  var HOUR = MIN * 60;
@@ -132,194 +76,6 @@
132
76
 
133
77
  return (d ? d + "d " : '') + h.toString().padStart(2, 0) + ':' + m.toString().padStart(2, 0) + "'" + s.toString().padStart(2, 0) + '"';
134
78
  }
135
- /**
136
- * Simple GeoJSON data loader.
137
- */
138
-
139
- function GeoJSONLoader(data, control) {
140
- if (typeof data === "string") {
141
- data = JSON.parse(data);
142
- }
143
-
144
- control = control || this;
145
- var distanceMarkers = control.options.distanceMarkers === true ? {
146
- lazy: true
147
- } : L.extend({
148
- lazy: true
149
- }, control.options.distanceMarkers);
150
- var _control$options = control.options,
151
- wptIcons = _control$options.wptIcons,
152
- wptLabels = _control$options.wptLabels; // Partially fix MultiLineStrings (trk > trkseg + trkseg) splitting them into seperate LineStrings (trk > trkseg, trk > trkseg)
153
-
154
- data.features.forEach(function (d) {
155
- if (d.type == 'Feature' && d.geometry.type == "MultiLineString") {
156
- d.geometry.coordinates.forEach(function (coords) {
157
- data.features.push({
158
- type: 'Feature',
159
- geometry: {
160
- type: 'LineString',
161
- coordinates: coords
162
- },
163
- properties: d.properties
164
- });
165
- });
166
- }
167
- });
168
- data.features = data.features.filter(function (d) {
169
- return d.type && d.geometry.type != "MultiLineString";
170
- });
171
- var layer = L.geoJson(data, {
172
- distanceMarkers: distanceMarkers,
173
- style: function style(feature) {
174
- var style = L.extend({}, control.options.polyline);
175
-
176
- if (control.options.theme) {
177
- style.className += ' ' + control.options.theme;
178
- }
179
-
180
- return style;
181
- },
182
- pointToLayer: function pointToLayer(feature, latlng) {
183
- var _prop$desc, _prop$name, _prop$sym;
184
-
185
- if (!control.options.waypoints) return;
186
- var prop = feature.properties;
187
- var desc = (_prop$desc = prop.desc) !== null && _prop$desc !== void 0 ? _prop$desc : '';
188
- var name = (_prop$name = prop.name) !== null && _prop$name !== void 0 ? _prop$name : '';
189
- var sym = ((_prop$sym = prop.sym) !== null && _prop$sym !== void 0 ? _prop$sym : name).replace(' ', '-').replace('"', '').replace("'", '').toLowerCase(); // Handle chart waypoints (dots)
190
-
191
- if ([true, 'dots'].includes(control.options.waypoints)) {
192
- control._registerCheckPoint({
193
- latlng: latlng,
194
- label: [true, 'dots'].includes(wptLabels) ? name : ''
195
- }, true);
196
- } // Handle map waypoints (markers)
197
-
198
-
199
- if ([true, 'markers'].includes(control.options.waypoints) && wptIcons != false) {
200
- // generate and cache appropriate icon symbol
201
- if (!wptIcons.hasOwnProperty(sym)) {
202
- wptIcons[sym] = L.divIcon(L.extend({}, wptIcons[""].options, {
203
- html: '<i class="elevation-waypoint-icon ' + sym + '"></i>'
204
- }));
205
- }
206
-
207
- var marker = L.marker(latlng, {
208
- icon: wptIcons[sym]
209
- });
210
-
211
- if ([true, 'markers'].includes(wptLabels) && (name || desc)) {
212
- marker.bindPopup("<b>" + name + "</b>" + (desc.length > 0 ? '<br>' + desc : '')).openPopup();
213
- }
214
-
215
- control._addMarker(marker);
216
-
217
- control.fire('waypoint_added', {
218
- point: marker,
219
- element: latlng,
220
- properties: prop
221
- });
222
- return marker;
223
- }
224
- },
225
- onEachFeature: function onEachFeature(feature, layer) {
226
- if (feature.geometry && feature.geometry.type == 'Point') return; // Standard GeoJSON
227
- // control.addData(feature, layer); // NB uses "_addGeoJSONData"
228
- // Extended GeoJSON
229
-
230
- layer._latlngs.forEach(function (point, i, data) {
231
- // same properties as L.GPX layer
232
- point.meta = {
233
- time: null,
234
- ele: null,
235
- hr: null,
236
- cad: null,
237
- atemp: null
238
- };
239
- if ("alt" in point) point.meta.ele = point.alt;
240
-
241
- if (feature.properties) {
242
- var prop = feature.properties;
243
- if ("coordTimes" in prop) point.meta.time = new Date(Date.parse(prop.coordTimes[i]));else if ("times" in prop) point.meta.time = new Date(Date.parse(prop.times[i]));else if ("time" in prop) point.meta.time = new Date(Date.parse(_typeof(prop.time) === 'object' ? prop.time[i] : prop.time));
244
- if ("heartRates" in prop) point.meta.hr = parseInt(prop.heartRates[i]);else if ("heartRate" in prop) point.meta.hr = parseInt(_typeof(prop.heartRate) === 'object' ? prop.heartRate[i] : prop.heartRate); // TODO: cadence, temperature
245
- }
246
- });
247
-
248
- control.addData(layer); // NB uses "_addGPXData"
249
- // Postpone adding the distance markers (lazy: true)
250
-
251
- if (control.options.distanceMarkers && distanceMarkers.lazy) {
252
- layer.on('add remove', function (e) {
253
- var path = e.target;
254
-
255
- if (L.DistanceMarkers && path instanceof L.Polyline) {
256
- path[e.type + 'DistanceMarkers']();
257
- }
258
- });
259
- }
260
-
261
- control.track_info = L.extend({}, control.track_info, {
262
- type: "geojson",
263
- name: data.name
264
- });
265
- }
266
- });
267
-
268
- L.Control.Elevation._d3LazyLoader.then(function () {
269
- control._fireEvt("eledata_loaded", {
270
- data: data,
271
- layer: layer,
272
- name: control.track_info.name,
273
- track_info: control.track_info
274
- });
275
- });
276
-
277
- return layer;
278
- }
279
- /**
280
- * Check object type.
281
- */
282
-
283
- function isObject(item) {
284
- return item && _typeof(item) === 'object' && !Array.isArray(item);
285
- }
286
- /**
287
- * Check JSON object type.
288
- */
289
-
290
- function isJSONDoc(doc, lazy) {
291
- lazy = typeof lazy === "undefined" ? true : lazy;
292
-
293
- if (typeof doc === "string" && lazy) {
294
- doc = doc.trim();
295
- return doc.indexOf("{") == 0 || doc.indexOf("[") == 0;
296
- } else {
297
- try {
298
- JSON.parse(doc.toString());
299
- } catch (e) {
300
- if (_typeof(doc) === "object" && lazy) return true;
301
- console.warn(e);
302
- return false;
303
- }
304
-
305
- return true;
306
- }
307
- }
308
- /**
309
- * Check XML object type.
310
- */
311
-
312
- function isXMLDoc(doc, lazy) {
313
- lazy = typeof lazy === "undefined" ? true : lazy;
314
-
315
- if (typeof doc === "string" && lazy) {
316
- doc = doc.trim();
317
- return doc.indexOf("<") == 0;
318
- } else {
319
- var documentElement = (doc ? doc.ownerDocument || doc : 0).documentElement;
320
- return documentElement ? documentElement.nodeName !== "HTML" : false;
321
- }
322
- }
323
79
  /**
324
80
  * Generate download data event.
325
81
  */
@@ -358,40 +114,6 @@
358
114
  document.head.appendChild(tag);
359
115
  });
360
116
  }
361
- function lazyLoad(src, control) {
362
- if (!control.options.lazyLoadJS) return Promise.resolve();
363
- var Elevation = L.Control.Elevation;
364
- var loader = '';
365
- var condition = false;
366
-
367
- switch (src) {
368
- case control.__D3:
369
- loader = '_d3LazyLoader';
370
- condition = (typeof d3 === "undefined" ? "undefined" : _typeof(d3)) !== 'object';
371
- break;
372
-
373
- case control.__TOGEOJSON:
374
- loader = '_togeojsonLazyLoader';
375
- condition = (typeof toGeoJSON === "undefined" ? "undefined" : _typeof(toGeoJSON)) !== 'object';
376
- break;
377
-
378
- case control.__LGEOMUTIL:
379
- loader = '_geomutilLazyLoader';
380
- condition = _typeof(L.GeometryUtil) !== 'object';
381
-
382
- case control.__LALMOSTOVER:
383
- loader = '_almostoverLazyLoader';
384
- condition = typeof L.Handler.AlmostOver !== 'function ';
385
- break;
386
-
387
- case control.__LDISTANCEM:
388
- loader = '_distanceMarkersLazyLoader';
389
- condition = typeof L.DistanceMarkers !== 'function';
390
- break;
391
- }
392
-
393
- return Elevation[loader] = lazyLoader(src, condition, Elevation[loader]);
394
- }
395
117
  /**
396
118
  * Convert SVG Path into Path2D and then update canvas
397
119
  */
@@ -530,15 +252,9 @@
530
252
 
531
253
  var _ = /*#__PURE__*/Object.freeze({
532
254
  __proto__: null,
533
- deepMerge: deepMerge,
534
255
  formatTime: formatTime,
535
- GeoJSONLoader: GeoJSONLoader,
536
- isObject: isObject,
537
- isJSONDoc: isJSONDoc,
538
- isXMLDoc: isXMLDoc,
539
256
  saveFile: saveFile,
540
257
  lazyLoader: lazyLoader,
541
- lazyLoad: lazyLoad,
542
258
  drawCanvas: drawCanvas,
543
259
  clamp: clamp,
544
260
  addClass: addClass,
@@ -1317,6 +1033,8 @@
1317
1033
  _this4.zooming = true;
1318
1034
  _this4._scales.distance = _this4._x = e.transform.rescaleX(_this4._x); // calculate x scale at zoom level
1319
1035
 
1036
+ if (_this4._scales.time) _this4._scales.time = e.transform.rescaleX(_this4._scales.time); // calculate x scale at zoom level
1037
+
1320
1038
  _this4._resetDrag();
1321
1039
 
1322
1040
  if (e.sourceEvent && e.sourceEvent.type == "mousemove") {
@@ -1479,7 +1197,9 @@
1479
1197
  var opts = this.options;
1480
1198
  var scale = props.scale;
1481
1199
 
1482
- if (typeof scale !== 'function') {
1200
+ if (typeof this._scales[props.name] === 'function') {
1201
+ props.scale = this._scales[props.name]; // retrieve cached scale
1202
+ } else if (typeof scale !== 'function') {
1483
1203
  scale = L.extend({
1484
1204
  data: this._data,
1485
1205
  forceBounds: opts.forceAxisBounds
@@ -1814,6 +1534,22 @@
1814
1534
  }
1815
1535
  });
1816
1536
 
1537
+ function _typeof(obj) {
1538
+ "@babel/helpers - typeof";
1539
+
1540
+ if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") {
1541
+ _typeof = function (obj) {
1542
+ return typeof obj;
1543
+ };
1544
+ } else {
1545
+ _typeof = function (obj) {
1546
+ return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
1547
+ };
1548
+ }
1549
+
1550
+ return _typeof(obj);
1551
+ }
1552
+
1817
1553
  var Marker = L.Class.extend({
1818
1554
  initialize: function initialize(options) {
1819
1555
  this.options = options;
@@ -2057,7 +1793,7 @@
2057
1793
  __TOGEOJSON: 'https://unpkg.com/@tmcw/togeojson@4.3.0/dist/togeojson.umd.js',
2058
1794
  __LGEOMUTIL: 'https://unpkg.com/leaflet-geometryutil@0.9.3/src/leaflet.geometryutil.js',
2059
1795
  __LALMOSTOVER: 'https://unpkg.com/leaflet-almostover@1.0.1/src/leaflet.almostover.js',
2060
- __LDISTANCEM: 'https://unpkg.com/@raruto/leaflet-elevation@1.8.3/libs/leaflet-distance-marker.min.js',
1796
+ __LDISTANCEM: 'https://unpkg.com/@raruto/leaflet-elevation@1.8.5/libs/leaflet-distance-marker.min.js',
2061
1797
 
2062
1798
  /*
2063
1799
  * Add data to the diagram either from GPX or GeoJSON and update the axis domain and data
@@ -2217,86 +1953,74 @@
2217
1953
  this._markers = L.featureGroup();
2218
1954
  this._markedSegments = L.polyline([]);
2219
1955
  this._chartEnabled = true, this.track_info = {};
2220
- this.options = deepMerge({}, this.options, options);
1956
+ L.setOptions(this, options);
2221
1957
  if (this.options.followMarker) this._setMapView = L.Util.throttle(this._setMapView, 300, this);
2222
1958
  if (this.options.legend) this.options.margins.bottom += 30;
2223
1959
  if (this.options.theme) this.options.polylineSegments.className += ' ' + this.options.theme;
2224
1960
  if (this.options.wptIcons === true) this.options.wptIcons = Options.wptIcons;
1961
+ if (this.options.distanceMarkers === true) this.options.distanceMarkers = {
1962
+ lazy: true
1963
+ };
2225
1964
 
2226
1965
  this._markedSegments.setStyle(this.options.polylineSegments); // Leaflet canvas renderer colors
2227
1966
 
2228
1967
 
2229
- L.extend(Colors, this.options.colors || {});
1968
+ L.extend(Colors, this.options.colors || {}); // Various stuff
1969
+
1970
+ this._fixCanvasPaths();
1971
+
1972
+ this._fixTooltipSize();
2230
1973
  },
2231
1974
 
2232
1975
  /**
2233
1976
  * Javascript scripts downloader (lazy loader)
2234
1977
  */
2235
- lazyLoad: function lazyLoad$1(src) {
2236
- return lazyLoad(src, this);
2237
- },
1978
+ lazyLoad: function lazyLoad(src) {
1979
+ var condition = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
1980
+ var loader = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : '';
2238
1981
 
2239
- /**
2240
- * Load elevation data (GPX, GeoJSON or KML).
2241
- */
2242
- load: function load(data) {
2243
- if (isXMLDoc(data)) {
2244
- this.loadXML(data);
2245
- } else if (isJSONDoc(data)) {
2246
- this.loadGeoJSON(data);
2247
- } else {
2248
- this.loadFile(data);
1982
+ if (!this.options.lazyLoadJS) {
1983
+ return Promise.resolve();
2249
1984
  }
2250
- },
2251
1985
 
2252
- /**
2253
- * Load data from a remote url.
2254
- */
2255
- loadFile: function loadFile(url) {
2256
- var _this3 = this;
1986
+ switch (src) {
1987
+ case this.__D3:
1988
+ loader = '_d3LazyLoader';
1989
+ condition = (typeof d3 === "undefined" ? "undefined" : _typeof(d3)) !== 'object';
1990
+ break;
2257
1991
 
2258
- fetch(url).then(function (response) {
2259
- return response.text();
2260
- }).then(function (data) {
2261
- _this3._downloadURL = url; // TODO: handle multiple urls?
1992
+ case this.__TOGEOJSON:
1993
+ loader = '_togeojsonLazyLoader';
1994
+ condition = (typeof toGeoJSON === "undefined" ? "undefined" : _typeof(toGeoJSON)) !== 'object';
1995
+ break;
2262
1996
 
2263
- _this3.load(data);
2264
- }).catch(function (err) {
2265
- return console.warn(err);
2266
- });
2267
- },
1997
+ case this.__LGEOMUTIL:
1998
+ loader = '_geomutilLazyLoader';
1999
+ condition = _typeof(L.GeometryUtil) !== 'object';
2000
+ break;
2268
2001
 
2269
- /**
2270
- * Load raw GeoJSON data.
2271
- */
2272
- loadGeoJSON: function loadGeoJSON(data) {
2273
- GeoJSONLoader(data, this);
2002
+ case this.__LALMOSTOVER:
2003
+ loader = '_almostoverLazyLoader';
2004
+ condition = typeof L.Handler.AlmostOver !== 'function';
2005
+ break;
2006
+
2007
+ case this.__LDISTANCEM:
2008
+ loader = '_distanceMarkersLazyLoader';
2009
+ condition = typeof L.DistanceMarkers !== 'function';
2010
+ break;
2011
+ }
2012
+
2013
+ return L.Control.Elevation[loader] = lazyLoader(src, condition, L.Control.Elevation[loader]);
2274
2014
  },
2275
2015
 
2276
2016
  /**
2277
- * Load raw XML data.
2017
+ * Load elevation data (GPX, GeoJSON or KML).
2278
2018
  */
2279
- loadXML: function loadXML(data) {
2280
- var _this4 = this;
2281
-
2282
- this.lazyLoad(this.__TOGEOJSON).then(function () {
2283
- var xml = new DOMParser().parseFromString(data, "text/xml");
2284
- var type = xml.documentElement.tagName.toLowerCase(); // "kml" or "gpx"
2285
-
2286
- if (!(type in toGeoJSON)) {
2287
- type = xml.documentElement.tagName == "TrainingCenterDatabase" ? 'tcx' : 'gpx';
2288
- }
2289
-
2290
- var geojson = toGeoJSON[type](xml);
2291
- var name = xml.getElementsByTagName('name');
2292
-
2293
- if (name[0]) {
2294
- geojson.name = name[0].innerHTML;
2295
- } else if (_this4._downloadURL) {
2296
- geojson.name = _this4._downloadURL.split('/').pop().split('#')[0].split('?')[0];
2297
- }
2019
+ load: function load(data) {
2020
+ var _this3 = this;
2298
2021
 
2299
- return _this4.loadGeoJSON(geojson, _this4);
2022
+ this._parseFromString(data).then(function (geojson) {
2023
+ return geojson ? _this3._loadLayer(geojson) : _this3._loadFile(data);
2300
2024
  });
2301
2025
  },
2302
2026
 
@@ -2305,38 +2029,36 @@
2305
2029
  * Called on control.addTo(map).
2306
2030
  */
2307
2031
  onAdd: function onAdd(map) {
2308
- var _this5 = this;
2032
+ var _this4 = this;
2309
2033
 
2310
2034
  this._map = map;
2311
2035
 
2312
- var container = this._container = create("div", "elevation-control elevation " + this.options.theme);
2313
-
2314
- if (!this.options.detached) {
2315
- addClass(container, 'leaflet-control');
2316
- }
2036
+ var container = this._container = create("div", "elevation-control elevation " + this.options.theme + " " + (this.options.detached ? '' : 'leaflet-control'));
2317
2037
 
2318
2038
  this.lazyLoad(this.__D3).then(function () {
2319
- _this5._initButton(container);
2039
+ _this4._initButton(container);
2040
+
2041
+ _this4._initChart(container);
2320
2042
 
2321
- _this5._initChart(container);
2043
+ _this4._initSummary(container);
2322
2044
 
2323
- _this5._initSummary(container);
2045
+ _this4._initMarker(map);
2324
2046
 
2325
- _this5._initMarker(map);
2047
+ _this4._initLayer(map);
2326
2048
 
2327
- _this5._initLayer(map);
2049
+ map.on('zoom viewreset zoomanim', _this4._hideMarker, _this4).on('resize', _this4._resetView, _this4).on('resize', _this4._resizeChart, _this4).on('rotate', _this4._rotateMarker, _this4).on('mousedown', _this4._resetDrag, _this4);
2328
2050
 
2329
- map.on('zoom viewreset zoomanim', _this5._hideMarker, _this5).on('resize', _this5._resetView, _this5).on('resize', _this5._resizeChart, _this5).on('rotate', _this5._rotateMarker, _this5).on('mousedown', _this5._resetDrag, _this5);
2051
+ on(map.getContainer(), 'mousewheel', _this4._resetDrag, _this4);
2330
2052
 
2331
- on(map.getContainer(), 'mousewheel', _this5._resetDrag, _this5);
2053
+ on(map.getContainer(), 'touchstart', _this4._resetDrag, _this4);
2332
2054
 
2333
- on(map.getContainer(), 'touchstart', _this5._resetDrag, _this5);
2055
+ on(document, 'keydown', _this4._keydownHandler, _this4);
2334
2056
 
2335
- _this5.on('eledata_added eledata_loaded', _this5._updateChart, _this5).on('eledata_added eledata_loaded', _this5._updateSummary, _this5);
2057
+ _this4.on('eledata_added eledata_loaded', _this4._updateChart, _this4).on('eledata_added eledata_loaded', _this4._updateSummary, _this4);
2336
2058
 
2337
- _this5._updateChart();
2059
+ _this4._updateChart();
2338
2060
 
2339
- _this5._updateSummary();
2061
+ _this4._updateSummary();
2340
2062
  });
2341
2063
  return container;
2342
2064
  },
@@ -2353,6 +2075,8 @@
2353
2075
 
2354
2076
  off(map.getContainer(), 'touchstart', this._resetDrag, this);
2355
2077
 
2078
+ off(document, 'keydown', this._keydownHandler, this);
2079
+
2356
2080
  this.off('eledata_added eledata_loaded', this._updateChart, this).off('eledata_added eledata_loaded', this._updateSummary, this);
2357
2081
  },
2358
2082
 
@@ -2381,7 +2105,7 @@
2381
2105
  * Parsing data either from GPX or GeoJSON and update the diagram data
2382
2106
  */
2383
2107
  _addData: function _addData(d) {
2384
- var _this6 = this;
2108
+ var _this5 = this;
2385
2109
 
2386
2110
  if (!d) {
2387
2111
  return;
@@ -2398,7 +2122,7 @@
2398
2122
 
2399
2123
  case 'MultiLineString':
2400
2124
  each(geom.coordinates, function (coords) {
2401
- return _this6._addGeoJSONData(coords);
2125
+ return _this5._addGeoJSONData(coords);
2402
2126
  });
2403
2127
 
2404
2128
  break;
@@ -2410,7 +2134,7 @@
2410
2134
 
2411
2135
  if (d.type === "FeatureCollection") {
2412
2136
  each(d.features, function (feature) {
2413
- return _this6._addData(feature);
2137
+ return _this5._addData(feature);
2414
2138
  });
2415
2139
  }
2416
2140
 
@@ -2423,14 +2147,14 @@
2423
2147
  * Parsing of GeoJSON data lines and their elevation in z-coordinate
2424
2148
  */
2425
2149
  _addGeoJSONData: function _addGeoJSONData(coords) {
2426
- var _this7 = this;
2150
+ var _this6 = this;
2427
2151
 
2428
2152
  each(coords, function (point) {
2429
- _this7._addPoint(point[1], point[0], point[2]);
2153
+ _this6._addPoint(point[1], point[0], point[2]);
2430
2154
 
2431
- _this7._fireEvt("elepoint_added", {
2155
+ _this6._fireEvt("elepoint_added", {
2432
2156
  point: point,
2433
- index: _this7._data.length - 1
2157
+ index: _this6._data.length - 1
2434
2158
  });
2435
2159
  });
2436
2160
 
@@ -2444,16 +2168,16 @@
2444
2168
  * Parsing function for GPX data and their elevation in z-coordinate
2445
2169
  */
2446
2170
  _addGPXData: function _addGPXData(coords) {
2447
- var _this8 = this;
2171
+ var _this7 = this;
2448
2172
 
2449
2173
  each(coords, function (point) {
2450
2174
  var _point$alt;
2451
2175
 
2452
- _this8._addPoint(point.lat, point.lng, (_point$alt = point.alt) !== null && _point$alt !== void 0 ? _point$alt : point.meta.ele);
2176
+ _this7._addPoint(point.lat, point.lng, (_point$alt = point.alt) !== null && _point$alt !== void 0 ? _point$alt : point.meta.ele);
2453
2177
 
2454
- _this8._fireEvt("elepoint_added", {
2178
+ _this7._fireEvt("elepoint_added", {
2455
2179
  point: point,
2456
- index: _this8._data.length - 1
2180
+ index: _this7._data.length - 1
2457
2181
  });
2458
2182
  });
2459
2183
 
@@ -2485,11 +2209,68 @@
2485
2209
  });
2486
2210
  },
2487
2211
  _addLayer: function _addLayer(layer) {
2488
- if (layer) this._layers.addLayer(layer);
2212
+ if (layer) this._layers.addLayer(layer); // Postpone adding the distance markers (lazy: true)
2213
+
2214
+ if (layer && this.options.distanceMarkers && this.options.distanceMarkers.lazy) {
2215
+ layer.on('add remove', function (e) {
2216
+ return L.DistanceMarkers && e.target instanceof L.Polyline && e.target[e.type + 'DistanceMarkers']();
2217
+ });
2218
+ }
2489
2219
  },
2490
2220
  _addMarker: function _addMarker(marker) {
2491
2221
  if (marker) this._markers.addLayer(marker);
2492
2222
  },
2223
+ _bindPopup: function _bindPopup(marker) {
2224
+ var popup = marker._popup;
2225
+
2226
+ if (popup) {
2227
+ popup.options.className = 'elevation-popup';
2228
+
2229
+ if (popup._content) {
2230
+ popup._content = decodeURI(popup._content);
2231
+ popup.bindTooltip(popup._content, {
2232
+ direction: 'auto',
2233
+ sticky: true,
2234
+ opacity: 1,
2235
+ className: 'elevation-tooltip'
2236
+ }).openTooltip();
2237
+ }
2238
+ }
2239
+ },
2240
+ _initAlmostOverHandler: function _initAlmostOverHandler(map, layer) {
2241
+ var _this8 = this;
2242
+
2243
+ if (!map || !this.options.almostOver) return;
2244
+ this.lazyLoad(this.__LGEOMUTIL).then(function () {
2245
+ return _this8.lazyLoad(_this8.__LALMOSTOVER);
2246
+ }).then(function () {
2247
+ map.addHandler('almostOver', L.Handler.AlmostOver);
2248
+
2249
+ if (L.GeometryUtil && map.almostOver && map.almostOver.enabled()) {
2250
+ map.almostOver.addLayer(layer);
2251
+ map.on('almost:move', function (e) {
2252
+ return _this8._mousemoveLayerHandler(e);
2253
+ }).on('almost:out', function (e) {
2254
+ return _this8._mouseoutHandler(e);
2255
+ });
2256
+ }
2257
+ });
2258
+ },
2259
+ _initDistanceMarkers: function _initDistanceMarkers(map, layer) {
2260
+ var _this9 = this;
2261
+
2262
+ if (!map) return;
2263
+
2264
+ if (this.options.distanceMarkers) {
2265
+ this.lazyLoad(this.__LGEOMUTIL).then(function () {
2266
+ return _this9.lazyLoad(_this9.__LDISTANCEM);
2267
+ }).then(function () {
2268
+ return _this9.options.polyline && layer.addTo(map);
2269
+ });
2270
+ } else if (this.options.polyline) {
2271
+ layer.addTo(map);
2272
+ }
2273
+ },
2493
2274
 
2494
2275
  /**
2495
2276
  * Adds the control to the given "detached" div.
@@ -2508,8 +2289,7 @@
2508
2289
  replaceClass(eleDiv, 'leaflet-control', 'elevation-detached');
2509
2290
  }
2510
2291
 
2511
- this.eleDiv = eleDiv;
2512
- return this.eleDiv;
2292
+ return this.eleDiv = eleDiv;
2513
2293
  },
2514
2294
 
2515
2295
  /*
@@ -2526,6 +2306,58 @@
2526
2306
  replaceClass(this._container, 'elevation-collapsed', 'elevation-expanded');
2527
2307
  },
2528
2308
 
2309
+ /**
2310
+ * Add some basic colors to leaflet canvas renderer (preferCanvas: true).
2311
+ */
2312
+ _fixCanvasPaths: function _fixCanvasPaths() {
2313
+ var oldProto = L.Canvas.prototype._fillStroke;
2314
+ var control = this;
2315
+ L.Canvas.include({
2316
+ _fillStroke: function _fillStroke(ctx, layer) {
2317
+ if (control._layers.hasLayer(layer)) {
2318
+ var theme = control.options.theme.replace('-theme', '');
2319
+ var color = Colors[theme] || {};
2320
+ var options = layer.options;
2321
+ options.color = color.line || color.area || theme;
2322
+ options.stroke = !!options.color;
2323
+ oldProto.call(this, ctx, layer);
2324
+
2325
+ if (options.stroke && options.weight !== 0) {
2326
+ var oldVal = ctx.globalCompositeOperation || 'source-over';
2327
+ ctx.globalCompositeOperation = 'destination-over';
2328
+ ctx.strokeStyle = color.outline || '#FFF';
2329
+ ctx.lineWidth = options.weight * 1.75;
2330
+ ctx.stroke();
2331
+ ctx.globalCompositeOperation = oldVal;
2332
+ }
2333
+ } else {
2334
+ oldProto.call(this, ctx, layer);
2335
+ }
2336
+ }
2337
+ });
2338
+ },
2339
+
2340
+ /**
2341
+ * Partial fix for initial tooltip size
2342
+ *
2343
+ * @link https://github.com/Raruto/leaflet-elevation/issues/81#issuecomment-713477050
2344
+ */
2345
+ _fixTooltipSize: function _fixTooltipSize() {
2346
+ var _this10 = this;
2347
+
2348
+ this.on('elechart_init', function () {
2349
+ return _this10.once('elechart_change elechart_hover', function (e) {
2350
+ if (_this10._chartEnabled) {
2351
+ _this10._chart._showDiagramIndicator(e.data, e.xCoord);
2352
+
2353
+ _this10._chart._showDiagramIndicator(e.data, e.xCoord);
2354
+ }
2355
+
2356
+ _this10._updateMarker(e.data);
2357
+ });
2358
+ });
2359
+ },
2360
+
2529
2361
  /*
2530
2362
  * Finds a data entry for the given LatLng
2531
2363
  */
@@ -2602,17 +2434,17 @@
2602
2434
  this._fireEvt("elechart_init");
2603
2435
  },
2604
2436
  _initLayer: function _initLayer() {
2605
- var _this9 = this;
2437
+ var _this11 = this;
2606
2438
 
2607
2439
  this._layers.on('layeradd layerremove', function (e) {
2608
2440
  var layer = e.layer;
2609
2441
  var node = layer.getElement && layer.getElement();
2610
2442
 
2611
- toggleClass(node, _this9.options.polyline.className + ' ' + _this9.options.theme, e.type == 'layeradd');
2443
+ toggleClass(node, _this11.options.polyline.className + ' ' + _this11.options.theme, e.type == 'layeradd');
2612
2444
 
2613
- toggleEvent(layer, "mousemove", _this9._mousemoveLayerHandler.bind(_this9), e.type == 'layeradd');
2445
+ toggleEvent(layer, "mousemove", _this11._mousemoveLayerHandler.bind(_this11), e.type == 'layeradd');
2614
2446
 
2615
- toggleEvent(layer, "mouseout", _this9._mouseoutHandler.bind(_this9), e.type == 'layeradd');
2447
+ toggleEvent(layer, "mouseout", _this11._mouseoutHandler.bind(_this11), e.type == 'layeradd');
2616
2448
  });
2617
2449
  },
2618
2450
  _initMarker: function _initMarker(map) {
@@ -2639,19 +2471,10 @@
2639
2471
  * Inspired by L.Control.Layers
2640
2472
  */
2641
2473
  _initButton: function _initButton(container) {
2642
- //Makes this work on IE10 Touch devices by stopping it from firing a mouseout event when the touch is released
2643
- container.setAttribute('aria-haspopup', true);
2644
-
2645
- if (!this.options.detached) {
2474
+ if (L.Browser.mobile || !this.options.detached) {
2646
2475
  L.DomEvent.disableClickPropagation(container).disableScrollPropagation(container);
2647
2476
  }
2648
2477
 
2649
- if (L.Browser.mobile) {
2650
- on(container, 'click', L.DomEvent.stopPropagation);
2651
- }
2652
-
2653
- on(container, 'mousewheel', this._mousewheelHandler, this);
2654
-
2655
2478
  if (!this.options.detached) {
2656
2479
  var link = this._button = create('a', "elevation-toggle elevation-toggle-icon" + (this.options.autohide ? "" : " close-button"), {
2657
2480
  href: '#',
@@ -2673,17 +2496,162 @@
2673
2496
 
2674
2497
  on(link, 'focus', this._toggle, this);
2675
2498
 
2676
- this._map.on('click', this._collapse, this); // TODO: keyboard accessibility
2677
-
2499
+ this._map.on('click', this._collapse, this);
2678
2500
  }
2679
2501
  }
2680
2502
  },
2681
2503
  _initSummary: function _initSummary(container) {
2682
- var summary = this._summary = new Summary({
2504
+ this._summary = new Summary({
2683
2505
  summary: this.options.summary
2684
2506
  }, this);
2685
- d3.select(container).call(summary.render());
2686
- this.summaryDiv = this._summary._container;
2507
+ d3.select(container).call(this._summary.render());
2508
+ },
2509
+ _keydownHandler: function _keydownHandler(e) {
2510
+ if (!this.options.detached && e.key === "Escape") {
2511
+ this._collapse();
2512
+ }
2513
+ },
2514
+
2515
+ /**
2516
+ * Retrieve data from a remote url (HTTP).
2517
+ */
2518
+ _loadFile: function _loadFile(url) {
2519
+ var _this12 = this;
2520
+
2521
+ fetch(url).then(function (response) {
2522
+ return response.text();
2523
+ }).then(function (data) {
2524
+ _this12._downloadURL = url; // TODO: handle multiple urls?
2525
+
2526
+ _this12._parseFromString(data).then(function (geojson) {
2527
+ return geojson && _this12._loadLayer(geojson);
2528
+ });
2529
+ }).catch(function (err) {
2530
+ return console.warn(err);
2531
+ });
2532
+ },
2533
+
2534
+ /**
2535
+ * Simple GeoJSON data loader (L.GeoJSON).
2536
+ */
2537
+ _loadLayer: function _loadLayer(geojson) {
2538
+ var control = this;
2539
+ var _control$options = control.options,
2540
+ wptIcons = _control$options.wptIcons,
2541
+ wptLabels = _control$options.wptLabels;
2542
+ var layer = L.geoJson(geojson, {
2543
+ distanceMarkers: control.options.distanceMarkers,
2544
+ style: function style(feature) {
2545
+ var style = L.extend({}, control.options.polyline);
2546
+
2547
+ if (control.options.theme) {
2548
+ style.className += ' ' + control.options.theme;
2549
+ }
2550
+
2551
+ return style;
2552
+ },
2553
+ pointToLayer: function pointToLayer(feature, latlng) {
2554
+ var _prop$desc, _prop$name, _prop$sym;
2555
+
2556
+ if (!control.options.waypoints) return;
2557
+ var prop = feature.properties;
2558
+ var desc = (_prop$desc = prop.desc) !== null && _prop$desc !== void 0 ? _prop$desc : '';
2559
+ var name = (_prop$name = prop.name) !== null && _prop$name !== void 0 ? _prop$name : '';
2560
+ var sym = ((_prop$sym = prop.sym) !== null && _prop$sym !== void 0 ? _prop$sym : name).replace(' ', '-').replace('"', '').replace("'", '').toLowerCase(); // Handle chart waypoints (dots)
2561
+
2562
+ if ([true, 'dots'].includes(control.options.waypoints)) {
2563
+ control._registerCheckPoint({
2564
+ latlng: latlng,
2565
+ label: [true, 'dots'].includes(wptLabels) ? name : ''
2566
+ });
2567
+ } // Handle map waypoints (markers)
2568
+
2569
+
2570
+ if ([true, 'markers'].includes(control.options.waypoints) && wptIcons != false) {
2571
+ // generate and cache appropriate icon symbol
2572
+ if (!wptIcons.hasOwnProperty(sym)) {
2573
+ wptIcons[sym] = L.divIcon(L.extend({}, wptIcons[""].options, {
2574
+ html: '<i class="elevation-waypoint-icon ' + sym + '"></i>'
2575
+ }));
2576
+ }
2577
+
2578
+ var marker = L.marker(latlng, {
2579
+ icon: wptIcons[sym]
2580
+ });
2581
+
2582
+ if ([true, 'markers'].includes(wptLabels) && (name || desc)) {
2583
+ marker.bindPopup("<b>" + name + "</b>" + (desc.length > 0 ? '<br>' + desc : '')).openPopup();
2584
+ }
2585
+
2586
+ control._addMarker(marker);
2587
+
2588
+ control._bindPopup(marker);
2589
+
2590
+ control.fire('waypoint_added', {
2591
+ point: marker,
2592
+ element: latlng,
2593
+ properties: prop
2594
+ });
2595
+ return marker;
2596
+ }
2597
+ },
2598
+ onEachFeature: function onEachFeature(feature, layer) {
2599
+ if (feature.geometry && feature.geometry.type == 'Point') return; // Standard GeoJSON --> doesn't handle "time"
2600
+ // control.addData(feature, layer); // NB make use of "_addGeoJSONData"
2601
+ // Extended GeoJSON --> rely on leaflet implementation
2602
+
2603
+ layer._latlngs.forEach(function (point, i) {
2604
+ // same properties as L.GPX layer
2605
+ point.meta = {
2606
+ time: null,
2607
+ ele: null,
2608
+ hr: null,
2609
+ cad: null,
2610
+ atemp: null
2611
+ };
2612
+ if ("alt" in point) point.meta.ele = point.alt;
2613
+
2614
+ if (feature.properties) {
2615
+ var prop = feature.properties;
2616
+ if ("coordTimes" in prop) point.meta.time = new Date(Date.parse(prop.coordTimes[i]));else if ("times" in prop) point.meta.time = new Date(Date.parse(prop.times[i]));else if ("time" in prop) point.meta.time = new Date(Date.parse(_typeof(prop.time) === 'object' ? prop.time[i] : prop.time));
2617
+ if ("heartRates" in prop) point.meta.hr = parseInt(prop.heartRates[i]);else if ("heartRate" in prop) point.meta.hr = parseInt(_typeof(prop.heartRate) === 'object' ? prop.heartRate[i] : prop.heartRate); // TODO: cadence, temperature
2618
+ }
2619
+ });
2620
+
2621
+ control.addData(layer); // NB make use of "_addGPXData"
2622
+
2623
+ control.track_info = L.extend({}, control.track_info, {
2624
+ name: geojson.name
2625
+ });
2626
+ }
2627
+ });
2628
+ control.lazyLoad(control.__D3).then(function () {
2629
+ var map = control._map;
2630
+
2631
+ if (map) {
2632
+ map.once('layeradd', function (e) {
2633
+ return control.options.autofitBounds && control.fitBounds(layer.getBounds());
2634
+ });
2635
+
2636
+ if (!L.Browser.mobile) {
2637
+ control._initAlmostOverHandler(map, layer);
2638
+
2639
+ control._initDistanceMarkers(map, layer);
2640
+ } else if (control.options.polyline) {
2641
+ layer.addTo(map);
2642
+ }
2643
+ } else {
2644
+ console.warn("Undefined elevation map object");
2645
+ }
2646
+
2647
+ control._fireEvt("eledata_loaded", {
2648
+ data: geojson,
2649
+ layer: layer,
2650
+ name: control.track_info.name,
2651
+ track_info: control.track_info
2652
+ });
2653
+ });
2654
+ return layer;
2687
2655
  },
2688
2656
  _dragendHandler: function _dragendHandler(e) {
2689
2657
  this._hideMarker();
@@ -2767,29 +2735,116 @@
2767
2735
  this._fireEvt("elechart_leave");
2768
2736
  },
2769
2737
 
2770
- /*
2771
- * Handles the mouesewheel over the chart.
2738
+ /**
2739
+ * Simple GeoJSON Parser
2740
+ */
2741
+ _parseFromGeoJSONString: function _parseFromGeoJSONString(data) {
2742
+ try {
2743
+ return JSON.parse(data);
2744
+ } catch (e) {}
2745
+ },
2746
+
2747
+ /**
2748
+ * Attempt to parse raw response data (GeoJSON or XML > GeoJSON)
2772
2749
  */
2773
- _mousewheelHandler: function _mousewheelHandler(e) {
2774
- if (this._map.gestureHandling && this._map.gestureHandling._enabled) return;
2750
+ _parseFromString: function _parseFromString(data) {
2751
+ var _this13 = this;
2775
2752
 
2776
- var ll = this._marker.getLatLng() || this._map.getCenter();
2753
+ return new Promise(function (resolve) {
2754
+ return _this13.lazyLoad(_this13.__TOGEOJSON).then(function () {
2755
+ var geojson;
2777
2756
 
2778
- var z = this._map.getZoom() + Math.sign(e.deltaY);
2757
+ try {
2758
+ geojson = _this13._parseFromXMLString(data.trim());
2759
+ } catch (e) {
2760
+ geojson = _this13._parseFromGeoJSONString(data.toString());
2761
+ }
2779
2762
 
2780
- this._resetDrag();
2763
+ if (geojson) {
2764
+ geojson = _this13._prepareMultiLineStrings(geojson);
2765
+ geojson = _this13._prepareAdditionalProperties(geojson);
2766
+ }
2767
+
2768
+ resolve(geojson);
2769
+ });
2770
+ });
2771
+ },
2772
+
2773
+ /**
2774
+ * Simple XML Parser (GPX, KML, TCX)
2775
+ */
2776
+ _parseFromXMLString: function _parseFromXMLString(data) {
2777
+ var _Array$from$find;
2778
+
2779
+ if (data.indexOf("<") != 0) {
2780
+ throw 'Invalid XML';
2781
+ }
2782
+
2783
+ var xml = new DOMParser().parseFromString(data, "text/xml");
2784
+ var type = xml.documentElement.tagName.toLowerCase(); // "kml" or "gpx"
2785
+
2786
+ var name = xml.getElementsByTagName('name');
2787
+
2788
+ if (xml.getElementsByTagName('parsererror').length) {
2789
+ throw 'Invalid XML';
2790
+ }
2791
+
2792
+ if (!(type in toGeoJSON)) {
2793
+ type = xml.documentElement.tagName == "TrainingCenterDatabase" ? 'tcx' : 'gpx';
2794
+ }
2795
+
2796
+ var geojson = toGeoJSON[type](xml);
2797
+ geojson.name = name.length > 0 ? ((_Array$from$find = Array.from(name).find(function (tag) {
2798
+ return tag.parentElement.tagName == "trk";
2799
+ })) !== null && _Array$from$find !== void 0 ? _Array$from$find : name[0]).textContent : '';
2800
+ return geojson;
2801
+ },
2802
+
2803
+ /**
2804
+ * Extend GeoJSON properties (name, time, ...)
2805
+ */
2806
+ _prepareAdditionalProperties: function _prepareAdditionalProperties(geojson) {
2807
+ if (!geojson.name && this._downloadURL) {
2808
+ geojson.name = this._downloadURL.split('/').pop().split('#')[0].split('?')[0];
2809
+ }
2810
+
2811
+ return geojson;
2812
+ },
2781
2813
 
2782
- this._map.flyTo(ll, z);
2814
+ /**
2815
+ * Just a temporary fix for MultiLineString data (trk > trkseg + trkseg),
2816
+ * just split them into seperate LineStrings (trk > trkseg, trk > trkseg)
2817
+ *
2818
+ * @link https://github.com/Raruto/leaflet-elevation/issues/56
2819
+ */
2820
+ _prepareMultiLineStrings: function _prepareMultiLineStrings(geojson) {
2821
+ geojson.features.forEach(function (feauture) {
2822
+ if (feauture.geometry.type == "MultiLineString") {
2823
+ feauture.geometry.coordinates.forEach(function (coords) {
2824
+ geojson.features.push({
2825
+ geometry: {
2826
+ type: 'LineString',
2827
+ coordinates: coords
2828
+ },
2829
+ properties: feauture.properties,
2830
+ type: 'Feature'
2831
+ });
2832
+ });
2833
+ }
2834
+ });
2835
+ return geojson.features.filter(function (feauture) {
2836
+ return feauture.geometry.type != "MultiLineString";
2837
+ });
2783
2838
  },
2784
2839
 
2785
2840
  /**
2786
- * Add a waypoint marker to the diagram
2841
+ * Add a point of interest over the diagram
2787
2842
  */
2788
2843
  _registerCheckPoint: function _registerCheckPoint(props) {
2789
- var _this10 = this;
2844
+ var _this14 = this;
2790
2845
 
2791
2846
  this.on("elechart_updated", function () {
2792
- return _this10._chart._registerCheckPoint(props);
2847
+ return _this14._chart._registerCheckPoint(props);
2793
2848
  });
2794
2849
  },
2795
2850
 
@@ -2797,10 +2852,10 @@
2797
2852
  * Add chart profile to diagram
2798
2853
  */
2799
2854
  _registerAreaPath: function _registerAreaPath(props) {
2800
- var _this11 = this;
2855
+ var _this15 = this;
2801
2856
 
2802
2857
  this.on("elechart_init", function () {
2803
- return _this11._chart._registerAreaPath(props);
2858
+ return _this15._chart._registerAreaPath(props);
2804
2859
  });
2805
2860
  },
2806
2861
 
@@ -2808,10 +2863,10 @@
2808
2863
  * Add chart grid to diagram
2809
2864
  */
2810
2865
  _registerAxisGrid: function _registerAxisGrid(props) {
2811
- var _this12 = this;
2866
+ var _this16 = this;
2812
2867
 
2813
2868
  this.on("elechart_axis", function () {
2814
- return _this12._chart._registerAxisGrid(props);
2869
+ return _this16._chart._registerAxisGrid(props);
2815
2870
  });
2816
2871
  },
2817
2872
 
@@ -2819,10 +2874,10 @@
2819
2874
  * Add chart axis to diagram
2820
2875
  */
2821
2876
  _registerAxisScale: function _registerAxisScale(props) {
2822
- var _this13 = this;
2877
+ var _this17 = this;
2823
2878
 
2824
2879
  this.on("elechart_axis", function () {
2825
- return _this13._chart._registerAxisScale(props);
2880
+ return _this17._chart._registerAxisScale(props);
2826
2881
  });
2827
2882
  },
2828
2883
 
@@ -2830,14 +2885,14 @@
2830
2885
  * Add chart or marker tooltip info
2831
2886
  */
2832
2887
  _registerTooltip: function _registerTooltip(props) {
2833
- var _this14 = this;
2888
+ var _this18 = this;
2834
2889
 
2835
2890
  if (props.chart) {
2836
2891
  var label = L.extend({}, props, {
2837
2892
  value: props.chart
2838
2893
  });
2839
2894
  this.on("elechart_init", function () {
2840
- return _this14._chart._registerTooltip(label);
2895
+ return _this18._chart._registerTooltip(label);
2841
2896
  });
2842
2897
  }
2843
2898
 
@@ -2847,7 +2902,7 @@
2847
2902
  });
2848
2903
 
2849
2904
  this.on("elechart_marker", function () {
2850
- return _this14._marker._registerTooltip(_label);
2905
+ return _this18._marker._registerTooltip(_label);
2851
2906
  });
2852
2907
  }
2853
2908
  },
@@ -2856,10 +2911,10 @@
2856
2911
  * Add summary info to diagram
2857
2912
  */
2858
2913
  _registerSummary: function _registerSummary(props) {
2859
- var _this15 = this;
2914
+ var _this19 = this;
2860
2915
 
2861
2916
  this.on('elechart_summary', function () {
2862
- return _this15._summary._registerSummary(props);
2917
+ return _this19._summary._registerSummary(props);
2863
2918
  });
2864
2919
  },
2865
2920
 
@@ -2964,7 +3019,7 @@
2964
3019
  * Toggle chart data on legend click
2965
3020
  */
2966
3021
  _toggleChartHandler: function _toggleChartHandler(e) {
2967
- var _this16 = this;
3022
+ var _this20 = this;
2968
3023
 
2969
3024
  var path = e.path,
2970
3025
  name = e.name,
@@ -2974,7 +3029,7 @@
2974
3029
  this._layers.eachLayer(function (layer) {
2975
3030
  var node = layer.getElement && layer.getElement();
2976
3031
 
2977
- toggleClass(node, _this16.options.polyline.className + ' ' + _this16.options.theme, _this16._chartEnabled);
3032
+ toggleClass(node, _this20.options.polyline.className + ' ' + _this20.options.theme, _this20._chartEnabled);
2978
3033
  }); // toggle option value (eg. altitude = { 'disabled' || 'disabled' })
2979
3034
 
2980
3035
 
@@ -3048,7 +3103,7 @@
3048
3103
  * Update chart summary.
3049
3104
  */
3050
3105
  _updateSummary: function _updateSummary() {
3051
- var _this17 = this;
3106
+ var _this21 = this;
3052
3107
 
3053
3108
  this._summary.reset();
3054
3109
 
@@ -3058,14 +3113,22 @@
3058
3113
 
3059
3114
  if (this.options.downloadLink && this._downloadURL) {
3060
3115
  // TODO: generate dynamically file content instead of using static file urls.
3061
- this.summaryDiv.innerHTML += '<span class="download"><a href="#">' + L._('Download') + '</a></span>';
3116
+ this._summary._container.innerHTML += '<span class="download"><a href="#">' + L._('Download') + '</a></span>';
3062
3117
 
3063
- select('.download a', this.summaryDiv).onclick = function (e) {
3118
+ select('.download a', this._summary._container).onclick = function (e) {
3064
3119
  e.preventDefault();
3065
3120
 
3066
- _this17._fireEvt('eletrack_download', {
3067
- downloadLink: _this17.options.downloadLink,
3068
- confirm: saveFile.bind(_this17, _this17._downloadURL)
3121
+ if (e.downloadLink == 'modal' && typeof CustomEvent === "function") {
3122
+ document.dispatchEvent(new CustomEvent("eletrack_download", {
3123
+ detail: e
3124
+ }));
3125
+ } else if (e.downloadLink == 'link' || e.downloadLink === true) {
3126
+ e.confirm();
3127
+ }
3128
+
3129
+ _this21._fireEvt('eletrack_download', {
3130
+ downloadLink: _this21.options.downloadLink,
3131
+ confirm: saveFile.bind(_this21, _this21._downloadURL)
3069
3132
  });
3070
3133
  };
3071
3134
  }
@@ -3096,130 +3159,6 @@
3096
3159
  return this.__yTicks || Math.round(this._height() / 30);
3097
3160
  }
3098
3161
  });
3099
- /**
3100
- * Attach here some useful elevation hooks.
3101
- */
3102
-
3103
- Elevation.addInitHook(function () {
3104
- // Alias deprecated functions
3105
- this.enableDragging = this.enableBrush;
3106
- this.disableDragging = this.disableBrush;
3107
- this.loadChart = this.addTo;
3108
- this.loadData = this.load;
3109
- this.loadGPX = this.loadXML;
3110
- this.on('waypoint_added', function (e) {
3111
- var p = e.point,
3112
- pop = p._popup;
3113
-
3114
- if (pop) {
3115
- pop.options.className = 'elevation-popup';
3116
- }
3117
-
3118
- if (pop && pop._content) {
3119
- pop._content = decodeURI(pop._content);
3120
- p.bindTooltip(pop._content, {
3121
- direction: 'auto',
3122
- sticky: true,
3123
- opacity: 1,
3124
- className: 'elevation-tooltip'
3125
- }).openTooltip();
3126
- }
3127
- });
3128
- this.on("eletrack_download", function (e) {
3129
- if (e.downloadLink == 'modal' && typeof CustomEvent === "function") {
3130
- document.dispatchEvent(new CustomEvent("eletrack_download", {
3131
- detail: e
3132
- }));
3133
- } else if (e.downloadLink == 'link' || e.downloadLink === true) {
3134
- e.confirm();
3135
- }
3136
- });
3137
- this.on('eledata_loaded', function (e) {
3138
- var _this18 = this;
3139
-
3140
- var map = this._map;
3141
- var layer = e.layer;
3142
-
3143
- if (!map) {
3144
- console.warn("Undefined elevation map object");
3145
- return;
3146
- }
3147
-
3148
- map.once('layeradd', function (e) {
3149
- return _this18.options.autofitBounds && _this18.fitBounds(layer.getBounds());
3150
- });
3151
-
3152
- if (L.Browser.mobile) {
3153
- if (this.options.polyline) layer.addTo(map);
3154
- } else {
3155
- // leaflet-geometryutil
3156
- this.lazyLoad(this.__LGEOMUTIL).then(function () {
3157
- // leaflet-almostover
3158
- if (_this18.options.almostOver) {
3159
- _this18.lazyLoad(_this18.__LALMOSTOVER).then(function () {
3160
- map.addHandler('almostOver', L.Handler.AlmostOver);
3161
-
3162
- if (L.GeometryUtil && map.almostOver && map.almostOver.enabled()) {
3163
- map.almostOver.addLayer(layer);
3164
- map.on('almost:move', function (e) {
3165
- return _this18._mousemoveLayerHandler(e);
3166
- }).on('almost:out', function (e) {
3167
- return _this18._mouseoutHandler(e);
3168
- });
3169
- }
3170
- });
3171
- } // leaflet-distance-markers
3172
-
3173
-
3174
- if (_this18.options.distanceMarkers) {
3175
- _this18.lazyLoad(_this18.__LDISTANCEM).then(function () {
3176
- return _this18.options.polyline && layer.addTo(map);
3177
- });
3178
- } else {
3179
- if (_this18.options.polyline) layer.addTo(map);
3180
- }
3181
- });
3182
- }
3183
- }); // Basic canvas renderer support.
3184
-
3185
- var oldProto = L.Canvas.prototype._fillStroke;
3186
- var control = this;
3187
- L.Canvas.include({
3188
- _fillStroke: function _fillStroke(ctx, layer) {
3189
- if (control._layers.hasLayer(layer)) {
3190
- var theme = control.options.theme.replace('-theme', '');
3191
- var color = Colors[theme] || {};
3192
- var options = layer.options;
3193
- options.color = color.line || color.area || theme;
3194
- options.stroke = !!options.color;
3195
- oldProto.call(this, ctx, layer);
3196
-
3197
- if (options.stroke && options.weight !== 0) {
3198
- var oldVal = ctx.globalCompositeOperation || 'source-over';
3199
- ctx.globalCompositeOperation = 'destination-over';
3200
- ctx.strokeStyle = color.outline || '#FFF';
3201
- ctx.lineWidth = options.weight * 1.75;
3202
- ctx.stroke();
3203
- ctx.globalCompositeOperation = oldVal;
3204
- }
3205
- } else {
3206
- oldProto.call(this, ctx, layer);
3207
- }
3208
- }
3209
- }); // Partially fix: https://github.com/Raruto/leaflet-elevation/issues/81#issuecomment-713477050
3210
-
3211
- this.on('elechart_init', function () {
3212
- this.once('elechart_change elechart_hover', function (e) {
3213
- if (this._chartEnabled) {
3214
- this._chart._showDiagramIndicator(e.data, e.xCoord);
3215
-
3216
- this._chart._showDiagramIndicator(e.data, e.xCoord);
3217
- }
3218
-
3219
- this._updateMarker(e.data);
3220
- });
3221
- });
3222
- });
3223
3162
 
3224
3163
  Elevation.addInitHook(function () {
3225
3164
  var opts = this.options;
@@ -3900,7 +3839,19 @@
3900
3839
 
3901
3840
  return proto.call(null, string, data);
3902
3841
  };
3903
- })();
3842
+ })(); // Alias deprecated functions
3843
+
3844
+
3845
+ Elevation.addInitHook(function () {
3846
+ this.enableDragging = this.enableBrush;
3847
+ this.disableDragging = this.disableBrush;
3848
+ this.loadChart = this.addTo;
3849
+ this.loadData = this.load;
3850
+ this.loadGPX = this.load;
3851
+ this.loadGeoJSON = this.load;
3852
+ this.loadXML = this.load;
3853
+ this.loadFile = this.load;
3854
+ });
3904
3855
 
3905
3856
  L.control.elevation = function (options) {
3906
3857
  return new Elevation(options);