@raruto/leaflet-elevation 1.8.4 → 1.8.5

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,
@@ -1818,6 +1534,22 @@
1818
1534
  }
1819
1535
  });
1820
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
+
1821
1553
  var Marker = L.Class.extend({
1822
1554
  initialize: function initialize(options) {
1823
1555
  this.options = options;
@@ -2061,7 +1793,7 @@
2061
1793
  __TOGEOJSON: 'https://unpkg.com/@tmcw/togeojson@4.3.0/dist/togeojson.umd.js',
2062
1794
  __LGEOMUTIL: 'https://unpkg.com/leaflet-geometryutil@0.9.3/src/leaflet.geometryutil.js',
2063
1795
  __LALMOSTOVER: 'https://unpkg.com/leaflet-almostover@1.0.1/src/leaflet.almostover.js',
2064
- __LDISTANCEM: 'https://unpkg.com/@raruto/leaflet-elevation@1.8.4/libs/leaflet-distance-marker.min.js',
1796
+ __LDISTANCEM: 'https://unpkg.com/@raruto/leaflet-elevation@1.8.5/libs/leaflet-distance-marker.min.js',
2065
1797
 
2066
1798
  /*
2067
1799
  * Add data to the diagram either from GPX or GeoJSON and update the axis domain and data
@@ -2221,86 +1953,74 @@
2221
1953
  this._markers = L.featureGroup();
2222
1954
  this._markedSegments = L.polyline([]);
2223
1955
  this._chartEnabled = true, this.track_info = {};
2224
- this.options = deepMerge({}, this.options, options);
1956
+ L.setOptions(this, options);
2225
1957
  if (this.options.followMarker) this._setMapView = L.Util.throttle(this._setMapView, 300, this);
2226
1958
  if (this.options.legend) this.options.margins.bottom += 30;
2227
1959
  if (this.options.theme) this.options.polylineSegments.className += ' ' + this.options.theme;
2228
1960
  if (this.options.wptIcons === true) this.options.wptIcons = Options.wptIcons;
1961
+ if (this.options.distanceMarkers === true) this.options.distanceMarkers = {
1962
+ lazy: true
1963
+ };
2229
1964
 
2230
1965
  this._markedSegments.setStyle(this.options.polylineSegments); // Leaflet canvas renderer colors
2231
1966
 
2232
1967
 
2233
- L.extend(Colors, this.options.colors || {});
1968
+ L.extend(Colors, this.options.colors || {}); // Various stuff
1969
+
1970
+ this._fixCanvasPaths();
1971
+
1972
+ this._fixTooltipSize();
2234
1973
  },
2235
1974
 
2236
1975
  /**
2237
1976
  * Javascript scripts downloader (lazy loader)
2238
1977
  */
2239
- lazyLoad: function lazyLoad$1(src) {
2240
- return lazyLoad(src, this);
2241
- },
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] : '';
2242
1981
 
2243
- /**
2244
- * Load elevation data (GPX, GeoJSON or KML).
2245
- */
2246
- load: function load(data) {
2247
- if (isXMLDoc(data)) {
2248
- this.loadXML(data);
2249
- } else if (isJSONDoc(data)) {
2250
- this.loadGeoJSON(data);
2251
- } else {
2252
- this.loadFile(data);
1982
+ if (!this.options.lazyLoadJS) {
1983
+ return Promise.resolve();
2253
1984
  }
2254
- },
2255
1985
 
2256
- /**
2257
- * Load data from a remote url.
2258
- */
2259
- loadFile: function loadFile(url) {
2260
- var _this3 = this;
1986
+ switch (src) {
1987
+ case this.__D3:
1988
+ loader = '_d3LazyLoader';
1989
+ condition = (typeof d3 === "undefined" ? "undefined" : _typeof(d3)) !== 'object';
1990
+ break;
2261
1991
 
2262
- fetch(url).then(function (response) {
2263
- return response.text();
2264
- }).then(function (data) {
2265
- _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;
2266
1996
 
2267
- _this3.load(data);
2268
- }).catch(function (err) {
2269
- return console.warn(err);
2270
- });
2271
- },
1997
+ case this.__LGEOMUTIL:
1998
+ loader = '_geomutilLazyLoader';
1999
+ condition = _typeof(L.GeometryUtil) !== 'object';
2000
+ break;
2272
2001
 
2273
- /**
2274
- * Load raw GeoJSON data.
2275
- */
2276
- loadGeoJSON: function loadGeoJSON(data) {
2277
- 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]);
2278
2014
  },
2279
2015
 
2280
2016
  /**
2281
- * Load raw XML data.
2017
+ * Load elevation data (GPX, GeoJSON or KML).
2282
2018
  */
2283
- loadXML: function loadXML(data) {
2284
- var _this4 = this;
2285
-
2286
- this.lazyLoad(this.__TOGEOJSON).then(function () {
2287
- var xml = new DOMParser().parseFromString(data, "text/xml");
2288
- var type = xml.documentElement.tagName.toLowerCase(); // "kml" or "gpx"
2289
-
2290
- if (!(type in toGeoJSON)) {
2291
- type = xml.documentElement.tagName == "TrainingCenterDatabase" ? 'tcx' : 'gpx';
2292
- }
2293
-
2294
- var geojson = toGeoJSON[type](xml);
2295
- var name = xml.getElementsByTagName('name');
2296
-
2297
- if (name[0]) {
2298
- geojson.name = name[0].innerHTML;
2299
- } else if (_this4._downloadURL) {
2300
- geojson.name = _this4._downloadURL.split('/').pop().split('#')[0].split('?')[0];
2301
- }
2019
+ load: function load(data) {
2020
+ var _this3 = this;
2302
2021
 
2303
- return _this4.loadGeoJSON(geojson, _this4);
2022
+ this._parseFromString(data).then(function (geojson) {
2023
+ return geojson ? _this3._loadLayer(geojson) : _this3._loadFile(data);
2304
2024
  });
2305
2025
  },
2306
2026
 
@@ -2309,38 +2029,36 @@
2309
2029
  * Called on control.addTo(map).
2310
2030
  */
2311
2031
  onAdd: function onAdd(map) {
2312
- var _this5 = this;
2032
+ var _this4 = this;
2313
2033
 
2314
2034
  this._map = map;
2315
2035
 
2316
- var container = this._container = create("div", "elevation-control elevation " + this.options.theme);
2317
-
2318
- if (!this.options.detached) {
2319
- addClass(container, 'leaflet-control');
2320
- }
2036
+ var container = this._container = create("div", "elevation-control elevation " + this.options.theme + " " + (this.options.detached ? '' : 'leaflet-control'));
2321
2037
 
2322
2038
  this.lazyLoad(this.__D3).then(function () {
2323
- _this5._initButton(container);
2039
+ _this4._initButton(container);
2040
+
2041
+ _this4._initChart(container);
2324
2042
 
2325
- _this5._initChart(container);
2043
+ _this4._initSummary(container);
2326
2044
 
2327
- _this5._initSummary(container);
2045
+ _this4._initMarker(map);
2328
2046
 
2329
- _this5._initMarker(map);
2047
+ _this4._initLayer(map);
2330
2048
 
2331
- _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);
2332
2050
 
2333
- 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);
2334
2052
 
2335
- on(map.getContainer(), 'mousewheel', _this5._resetDrag, _this5);
2053
+ on(map.getContainer(), 'touchstart', _this4._resetDrag, _this4);
2336
2054
 
2337
- on(map.getContainer(), 'touchstart', _this5._resetDrag, _this5);
2055
+ on(document, 'keydown', _this4._keydownHandler, _this4);
2338
2056
 
2339
- _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);
2340
2058
 
2341
- _this5._updateChart();
2059
+ _this4._updateChart();
2342
2060
 
2343
- _this5._updateSummary();
2061
+ _this4._updateSummary();
2344
2062
  });
2345
2063
  return container;
2346
2064
  },
@@ -2357,6 +2075,8 @@
2357
2075
 
2358
2076
  off(map.getContainer(), 'touchstart', this._resetDrag, this);
2359
2077
 
2078
+ off(document, 'keydown', this._keydownHandler, this);
2079
+
2360
2080
  this.off('eledata_added eledata_loaded', this._updateChart, this).off('eledata_added eledata_loaded', this._updateSummary, this);
2361
2081
  },
2362
2082
 
@@ -2385,7 +2105,7 @@
2385
2105
  * Parsing data either from GPX or GeoJSON and update the diagram data
2386
2106
  */
2387
2107
  _addData: function _addData(d) {
2388
- var _this6 = this;
2108
+ var _this5 = this;
2389
2109
 
2390
2110
  if (!d) {
2391
2111
  return;
@@ -2402,7 +2122,7 @@
2402
2122
 
2403
2123
  case 'MultiLineString':
2404
2124
  each(geom.coordinates, function (coords) {
2405
- return _this6._addGeoJSONData(coords);
2125
+ return _this5._addGeoJSONData(coords);
2406
2126
  });
2407
2127
 
2408
2128
  break;
@@ -2414,7 +2134,7 @@
2414
2134
 
2415
2135
  if (d.type === "FeatureCollection") {
2416
2136
  each(d.features, function (feature) {
2417
- return _this6._addData(feature);
2137
+ return _this5._addData(feature);
2418
2138
  });
2419
2139
  }
2420
2140
 
@@ -2427,14 +2147,14 @@
2427
2147
  * Parsing of GeoJSON data lines and their elevation in z-coordinate
2428
2148
  */
2429
2149
  _addGeoJSONData: function _addGeoJSONData(coords) {
2430
- var _this7 = this;
2150
+ var _this6 = this;
2431
2151
 
2432
2152
  each(coords, function (point) {
2433
- _this7._addPoint(point[1], point[0], point[2]);
2153
+ _this6._addPoint(point[1], point[0], point[2]);
2434
2154
 
2435
- _this7._fireEvt("elepoint_added", {
2155
+ _this6._fireEvt("elepoint_added", {
2436
2156
  point: point,
2437
- index: _this7._data.length - 1
2157
+ index: _this6._data.length - 1
2438
2158
  });
2439
2159
  });
2440
2160
 
@@ -2448,16 +2168,16 @@
2448
2168
  * Parsing function for GPX data and their elevation in z-coordinate
2449
2169
  */
2450
2170
  _addGPXData: function _addGPXData(coords) {
2451
- var _this8 = this;
2171
+ var _this7 = this;
2452
2172
 
2453
2173
  each(coords, function (point) {
2454
2174
  var _point$alt;
2455
2175
 
2456
- _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);
2457
2177
 
2458
- _this8._fireEvt("elepoint_added", {
2178
+ _this7._fireEvt("elepoint_added", {
2459
2179
  point: point,
2460
- index: _this8._data.length - 1
2180
+ index: _this7._data.length - 1
2461
2181
  });
2462
2182
  });
2463
2183
 
@@ -2489,11 +2209,68 @@
2489
2209
  });
2490
2210
  },
2491
2211
  _addLayer: function _addLayer(layer) {
2492
- 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
+ }
2493
2219
  },
2494
2220
  _addMarker: function _addMarker(marker) {
2495
2221
  if (marker) this._markers.addLayer(marker);
2496
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
+ },
2497
2274
 
2498
2275
  /**
2499
2276
  * Adds the control to the given "detached" div.
@@ -2512,8 +2289,7 @@
2512
2289
  replaceClass(eleDiv, 'leaflet-control', 'elevation-detached');
2513
2290
  }
2514
2291
 
2515
- this.eleDiv = eleDiv;
2516
- return this.eleDiv;
2292
+ return this.eleDiv = eleDiv;
2517
2293
  },
2518
2294
 
2519
2295
  /*
@@ -2530,6 +2306,58 @@
2530
2306
  replaceClass(this._container, 'elevation-collapsed', 'elevation-expanded');
2531
2307
  },
2532
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
+
2533
2361
  /*
2534
2362
  * Finds a data entry for the given LatLng
2535
2363
  */
@@ -2606,17 +2434,17 @@
2606
2434
  this._fireEvt("elechart_init");
2607
2435
  },
2608
2436
  _initLayer: function _initLayer() {
2609
- var _this9 = this;
2437
+ var _this11 = this;
2610
2438
 
2611
2439
  this._layers.on('layeradd layerremove', function (e) {
2612
2440
  var layer = e.layer;
2613
2441
  var node = layer.getElement && layer.getElement();
2614
2442
 
2615
- 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');
2616
2444
 
2617
- toggleEvent(layer, "mousemove", _this9._mousemoveLayerHandler.bind(_this9), e.type == 'layeradd');
2445
+ toggleEvent(layer, "mousemove", _this11._mousemoveLayerHandler.bind(_this11), e.type == 'layeradd');
2618
2446
 
2619
- toggleEvent(layer, "mouseout", _this9._mouseoutHandler.bind(_this9), e.type == 'layeradd');
2447
+ toggleEvent(layer, "mouseout", _this11._mouseoutHandler.bind(_this11), e.type == 'layeradd');
2620
2448
  });
2621
2449
  },
2622
2450
  _initMarker: function _initMarker(map) {
@@ -2643,19 +2471,10 @@
2643
2471
  * Inspired by L.Control.Layers
2644
2472
  */
2645
2473
  _initButton: function _initButton(container) {
2646
- //Makes this work on IE10 Touch devices by stopping it from firing a mouseout event when the touch is released
2647
- container.setAttribute('aria-haspopup', true);
2648
-
2649
- if (!this.options.detached) {
2474
+ if (L.Browser.mobile || !this.options.detached) {
2650
2475
  L.DomEvent.disableClickPropagation(container).disableScrollPropagation(container);
2651
2476
  }
2652
2477
 
2653
- if (L.Browser.mobile) {
2654
- on(container, 'click', L.DomEvent.stopPropagation);
2655
- }
2656
-
2657
- on(container, 'mousewheel', this._mousewheelHandler, this);
2658
-
2659
2478
  if (!this.options.detached) {
2660
2479
  var link = this._button = create('a', "elevation-toggle elevation-toggle-icon" + (this.options.autohide ? "" : " close-button"), {
2661
2480
  href: '#',
@@ -2677,17 +2496,160 @@
2677
2496
 
2678
2497
  on(link, 'focus', this._toggle, this);
2679
2498
 
2680
- this._map.on('click', this._collapse, this); // TODO: keyboard accessibility
2681
-
2499
+ this._map.on('click', this._collapse, this);
2682
2500
  }
2683
2501
  }
2684
2502
  },
2685
2503
  _initSummary: function _initSummary(container) {
2686
- var summary = this._summary = new Summary({
2504
+ this._summary = new Summary({
2687
2505
  summary: this.options.summary
2688
2506
  }, this);
2689
- d3.select(container).call(summary.render());
2690
- 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.load(data);
2527
+ }).catch(function (err) {
2528
+ return console.warn(err);
2529
+ });
2530
+ },
2531
+
2532
+ /**
2533
+ * Simple GeoJSON data loader (L.GeoJSON).
2534
+ */
2535
+ _loadLayer: function _loadLayer(geojson) {
2536
+ var control = this;
2537
+ var _control$options = control.options,
2538
+ wptIcons = _control$options.wptIcons,
2539
+ wptLabels = _control$options.wptLabels;
2540
+ var layer = L.geoJson(geojson, {
2541
+ distanceMarkers: control.options.distanceMarkers,
2542
+ style: function style(feature) {
2543
+ var style = L.extend({}, control.options.polyline);
2544
+
2545
+ if (control.options.theme) {
2546
+ style.className += ' ' + control.options.theme;
2547
+ }
2548
+
2549
+ return style;
2550
+ },
2551
+ pointToLayer: function pointToLayer(feature, latlng) {
2552
+ var _prop$desc, _prop$name, _prop$sym;
2553
+
2554
+ if (!control.options.waypoints) return;
2555
+ var prop = feature.properties;
2556
+ var desc = (_prop$desc = prop.desc) !== null && _prop$desc !== void 0 ? _prop$desc : '';
2557
+ var name = (_prop$name = prop.name) !== null && _prop$name !== void 0 ? _prop$name : '';
2558
+ var sym = ((_prop$sym = prop.sym) !== null && _prop$sym !== void 0 ? _prop$sym : name).replace(' ', '-').replace('"', '').replace("'", '').toLowerCase(); // Handle chart waypoints (dots)
2559
+
2560
+ if ([true, 'dots'].includes(control.options.waypoints)) {
2561
+ control._registerCheckPoint({
2562
+ latlng: latlng,
2563
+ label: [true, 'dots'].includes(wptLabels) ? name : ''
2564
+ });
2565
+ } // Handle map waypoints (markers)
2566
+
2567
+
2568
+ if ([true, 'markers'].includes(control.options.waypoints) && wptIcons != false) {
2569
+ // generate and cache appropriate icon symbol
2570
+ if (!wptIcons.hasOwnProperty(sym)) {
2571
+ wptIcons[sym] = L.divIcon(L.extend({}, wptIcons[""].options, {
2572
+ html: '<i class="elevation-waypoint-icon ' + sym + '"></i>'
2573
+ }));
2574
+ }
2575
+
2576
+ var marker = L.marker(latlng, {
2577
+ icon: wptIcons[sym]
2578
+ });
2579
+
2580
+ if ([true, 'markers'].includes(wptLabels) && (name || desc)) {
2581
+ marker.bindPopup("<b>" + name + "</b>" + (desc.length > 0 ? '<br>' + desc : '')).openPopup();
2582
+ }
2583
+
2584
+ control._addMarker(marker);
2585
+
2586
+ control._bindPopup(marker);
2587
+
2588
+ control.fire('waypoint_added', {
2589
+ point: marker,
2590
+ element: latlng,
2591
+ properties: prop
2592
+ });
2593
+ return marker;
2594
+ }
2595
+ },
2596
+ onEachFeature: function onEachFeature(feature, layer) {
2597
+ if (feature.geometry && feature.geometry.type == 'Point') return; // Standard GeoJSON --> doesn't handle "time"
2598
+ // control.addData(feature, layer); // NB make use of "_addGeoJSONData"
2599
+ // Extended GeoJSON --> rely on leaflet implementation
2600
+
2601
+ layer._latlngs.forEach(function (point, i) {
2602
+ // same properties as L.GPX layer
2603
+ point.meta = {
2604
+ time: null,
2605
+ ele: null,
2606
+ hr: null,
2607
+ cad: null,
2608
+ atemp: null
2609
+ };
2610
+ if ("alt" in point) point.meta.ele = point.alt;
2611
+
2612
+ if (feature.properties) {
2613
+ var prop = feature.properties;
2614
+ 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));
2615
+ 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
2616
+ }
2617
+ });
2618
+
2619
+ control.addData(layer); // NB make use of "_addGPXData"
2620
+
2621
+ control.track_info = L.extend({}, control.track_info, {
2622
+ name: geojson.name
2623
+ });
2624
+ }
2625
+ });
2626
+ control.lazyLoad(control.__D3).then(function () {
2627
+ var map = control._map;
2628
+
2629
+ if (map) {
2630
+ map.once('layeradd', function (e) {
2631
+ return control.options.autofitBounds && control.fitBounds(layer.getBounds());
2632
+ });
2633
+
2634
+ if (!L.Browser.mobile) {
2635
+ control._initAlmostOverHandler(map, layer);
2636
+
2637
+ control._initDistanceMarkers(map, layer);
2638
+ } else if (control.options.polyline) {
2639
+ layer.addTo(map);
2640
+ }
2641
+ } else {
2642
+ console.warn("Undefined elevation map object");
2643
+ }
2644
+
2645
+ control._fireEvt("eledata_loaded", {
2646
+ data: geojson,
2647
+ layer: layer,
2648
+ name: control.track_info.name,
2649
+ track_info: control.track_info
2650
+ });
2651
+ });
2652
+ return layer;
2691
2653
  },
2692
2654
  _dragendHandler: function _dragendHandler(e) {
2693
2655
  this._hideMarker();
@@ -2771,29 +2733,114 @@
2771
2733
  this._fireEvt("elechart_leave");
2772
2734
  },
2773
2735
 
2774
- /*
2775
- * Handles the mouesewheel over the chart.
2736
+ /**
2737
+ * Simple GeoJSON Parser
2738
+ */
2739
+ _parseFromGeoJSONString: function _parseFromGeoJSONString(data) {
2740
+ try {
2741
+ return JSON.parse(data);
2742
+ } catch (e) {}
2743
+ },
2744
+
2745
+ /**
2746
+ * Attempt to parse raw response data (GeoJSON or XML > GeoJSON)
2776
2747
  */
2777
- _mousewheelHandler: function _mousewheelHandler(e) {
2778
- if (this._map.gestureHandling && this._map.gestureHandling._enabled) return;
2748
+ _parseFromString: function _parseFromString(data) {
2749
+ var _this13 = this;
2779
2750
 
2780
- var ll = this._marker.getLatLng() || this._map.getCenter();
2751
+ return new Promise(function (resolve) {
2752
+ return _this13.lazyLoad(_this13.__TOGEOJSON).then(function () {
2753
+ var geojson;
2781
2754
 
2782
- var z = this._map.getZoom() + Math.sign(e.deltaY);
2755
+ try {
2756
+ geojson = _this13._parseFromXMLString(data.trim());
2757
+ } catch (e) {
2758
+ geojson = _this13._parseFromGeoJSONString(data.toString());
2759
+ }
2783
2760
 
2784
- this._resetDrag();
2761
+ if (geojson) {
2762
+ geojson = _this13._prepareMultiLineStrings(geojson);
2763
+ geojson = _this13._prepareAdditionalProperties(geojson);
2764
+ }
2785
2765
 
2786
- this._map.flyTo(ll, z);
2766
+ resolve(geojson);
2767
+ });
2768
+ });
2787
2769
  },
2788
2770
 
2789
2771
  /**
2790
- * Add a waypoint marker to the diagram
2772
+ * Simple XML Parser (GPX, KML, TCX)
2773
+ */
2774
+ _parseFromXMLString: function _parseFromXMLString(data) {
2775
+ if (data.indexOf("<") != 0) {
2776
+ throw 'Invalid XML';
2777
+ }
2778
+
2779
+ var xml = new DOMParser().parseFromString(data, "text/xml");
2780
+ var type = xml.documentElement.tagName.toLowerCase(); // "kml" or "gpx"
2781
+
2782
+ var name = xml.getElementsByTagName('name');
2783
+
2784
+ if (xml.getElementsByTagName('parsererror').length) {
2785
+ throw 'Invalid XML';
2786
+ }
2787
+
2788
+ if (!(type in toGeoJSON)) {
2789
+ type = xml.documentElement.tagName == "TrainingCenterDatabase" ? 'tcx' : 'gpx';
2790
+ }
2791
+
2792
+ var geojson = toGeoJSON[type](xml);
2793
+ geojson.name = name.length > 0 ? Array.from(name).find(function (tag) {
2794
+ return tag.parentElement.tagName == "trk";
2795
+ }).textContent : '';
2796
+ return geojson;
2797
+ },
2798
+
2799
+ /**
2800
+ * Extend GeoJSON properties (name, time, ...)
2801
+ */
2802
+ _prepareAdditionalProperties: function _prepareAdditionalProperties(geojson) {
2803
+ if (!geojson.name && this._downloadURL) {
2804
+ geojson.name = this._downloadURL.split('/').pop().split('#')[0].split('?')[0];
2805
+ }
2806
+
2807
+ return geojson;
2808
+ },
2809
+
2810
+ /**
2811
+ * Just a temporary fix for MultiLineString data (trk > trkseg + trkseg),
2812
+ * just split them into seperate LineStrings (trk > trkseg, trk > trkseg)
2813
+ *
2814
+ * @link https://github.com/Raruto/leaflet-elevation/issues/56
2815
+ */
2816
+ _prepareMultiLineStrings: function _prepareMultiLineStrings(geojson) {
2817
+ geojson.features.forEach(function (feauture) {
2818
+ if (feauture.geometry.type == "MultiLineString") {
2819
+ feauture.geometry.coordinates.forEach(function (coords) {
2820
+ geojson.features.push({
2821
+ geometry: {
2822
+ type: 'LineString',
2823
+ coordinates: coords
2824
+ },
2825
+ properties: feauture.properties,
2826
+ type: 'Feature'
2827
+ });
2828
+ });
2829
+ }
2830
+ });
2831
+ return geojson.features.filter(function (feauture) {
2832
+ return feauture.geometry.type != "MultiLineString";
2833
+ });
2834
+ },
2835
+
2836
+ /**
2837
+ * Add a point of interest over the diagram
2791
2838
  */
2792
2839
  _registerCheckPoint: function _registerCheckPoint(props) {
2793
- var _this10 = this;
2840
+ var _this14 = this;
2794
2841
 
2795
2842
  this.on("elechart_updated", function () {
2796
- return _this10._chart._registerCheckPoint(props);
2843
+ return _this14._chart._registerCheckPoint(props);
2797
2844
  });
2798
2845
  },
2799
2846
 
@@ -2801,10 +2848,10 @@
2801
2848
  * Add chart profile to diagram
2802
2849
  */
2803
2850
  _registerAreaPath: function _registerAreaPath(props) {
2804
- var _this11 = this;
2851
+ var _this15 = this;
2805
2852
 
2806
2853
  this.on("elechart_init", function () {
2807
- return _this11._chart._registerAreaPath(props);
2854
+ return _this15._chart._registerAreaPath(props);
2808
2855
  });
2809
2856
  },
2810
2857
 
@@ -2812,10 +2859,10 @@
2812
2859
  * Add chart grid to diagram
2813
2860
  */
2814
2861
  _registerAxisGrid: function _registerAxisGrid(props) {
2815
- var _this12 = this;
2862
+ var _this16 = this;
2816
2863
 
2817
2864
  this.on("elechart_axis", function () {
2818
- return _this12._chart._registerAxisGrid(props);
2865
+ return _this16._chart._registerAxisGrid(props);
2819
2866
  });
2820
2867
  },
2821
2868
 
@@ -2823,10 +2870,10 @@
2823
2870
  * Add chart axis to diagram
2824
2871
  */
2825
2872
  _registerAxisScale: function _registerAxisScale(props) {
2826
- var _this13 = this;
2873
+ var _this17 = this;
2827
2874
 
2828
2875
  this.on("elechart_axis", function () {
2829
- return _this13._chart._registerAxisScale(props);
2876
+ return _this17._chart._registerAxisScale(props);
2830
2877
  });
2831
2878
  },
2832
2879
 
@@ -2834,14 +2881,14 @@
2834
2881
  * Add chart or marker tooltip info
2835
2882
  */
2836
2883
  _registerTooltip: function _registerTooltip(props) {
2837
- var _this14 = this;
2884
+ var _this18 = this;
2838
2885
 
2839
2886
  if (props.chart) {
2840
2887
  var label = L.extend({}, props, {
2841
2888
  value: props.chart
2842
2889
  });
2843
2890
  this.on("elechart_init", function () {
2844
- return _this14._chart._registerTooltip(label);
2891
+ return _this18._chart._registerTooltip(label);
2845
2892
  });
2846
2893
  }
2847
2894
 
@@ -2851,7 +2898,7 @@
2851
2898
  });
2852
2899
 
2853
2900
  this.on("elechart_marker", function () {
2854
- return _this14._marker._registerTooltip(_label);
2901
+ return _this18._marker._registerTooltip(_label);
2855
2902
  });
2856
2903
  }
2857
2904
  },
@@ -2860,10 +2907,10 @@
2860
2907
  * Add summary info to diagram
2861
2908
  */
2862
2909
  _registerSummary: function _registerSummary(props) {
2863
- var _this15 = this;
2910
+ var _this19 = this;
2864
2911
 
2865
2912
  this.on('elechart_summary', function () {
2866
- return _this15._summary._registerSummary(props);
2913
+ return _this19._summary._registerSummary(props);
2867
2914
  });
2868
2915
  },
2869
2916
 
@@ -2968,7 +3015,7 @@
2968
3015
  * Toggle chart data on legend click
2969
3016
  */
2970
3017
  _toggleChartHandler: function _toggleChartHandler(e) {
2971
- var _this16 = this;
3018
+ var _this20 = this;
2972
3019
 
2973
3020
  var path = e.path,
2974
3021
  name = e.name,
@@ -2978,7 +3025,7 @@
2978
3025
  this._layers.eachLayer(function (layer) {
2979
3026
  var node = layer.getElement && layer.getElement();
2980
3027
 
2981
- toggleClass(node, _this16.options.polyline.className + ' ' + _this16.options.theme, _this16._chartEnabled);
3028
+ toggleClass(node, _this20.options.polyline.className + ' ' + _this20.options.theme, _this20._chartEnabled);
2982
3029
  }); // toggle option value (eg. altitude = { 'disabled' || 'disabled' })
2983
3030
 
2984
3031
 
@@ -3052,7 +3099,7 @@
3052
3099
  * Update chart summary.
3053
3100
  */
3054
3101
  _updateSummary: function _updateSummary() {
3055
- var _this17 = this;
3102
+ var _this21 = this;
3056
3103
 
3057
3104
  this._summary.reset();
3058
3105
 
@@ -3062,14 +3109,22 @@
3062
3109
 
3063
3110
  if (this.options.downloadLink && this._downloadURL) {
3064
3111
  // TODO: generate dynamically file content instead of using static file urls.
3065
- this.summaryDiv.innerHTML += '<span class="download"><a href="#">' + L._('Download') + '</a></span>';
3112
+ this._summary._container.innerHTML += '<span class="download"><a href="#">' + L._('Download') + '</a></span>';
3066
3113
 
3067
- select('.download a', this.summaryDiv).onclick = function (e) {
3114
+ select('.download a', this._summary._container).onclick = function (e) {
3068
3115
  e.preventDefault();
3069
3116
 
3070
- _this17._fireEvt('eletrack_download', {
3071
- downloadLink: _this17.options.downloadLink,
3072
- confirm: saveFile.bind(_this17, _this17._downloadURL)
3117
+ if (e.downloadLink == 'modal' && typeof CustomEvent === "function") {
3118
+ document.dispatchEvent(new CustomEvent("eletrack_download", {
3119
+ detail: e
3120
+ }));
3121
+ } else if (e.downloadLink == 'link' || e.downloadLink === true) {
3122
+ e.confirm();
3123
+ }
3124
+
3125
+ _this21._fireEvt('eletrack_download', {
3126
+ downloadLink: _this21.options.downloadLink,
3127
+ confirm: saveFile.bind(_this21, _this21._downloadURL)
3073
3128
  });
3074
3129
  };
3075
3130
  }
@@ -3100,130 +3155,6 @@
3100
3155
  return this.__yTicks || Math.round(this._height() / 30);
3101
3156
  }
3102
3157
  });
3103
- /**
3104
- * Attach here some useful elevation hooks.
3105
- */
3106
-
3107
- Elevation.addInitHook(function () {
3108
- // Alias deprecated functions
3109
- this.enableDragging = this.enableBrush;
3110
- this.disableDragging = this.disableBrush;
3111
- this.loadChart = this.addTo;
3112
- this.loadData = this.load;
3113
- this.loadGPX = this.loadXML;
3114
- this.on('waypoint_added', function (e) {
3115
- var p = e.point,
3116
- pop = p._popup;
3117
-
3118
- if (pop) {
3119
- pop.options.className = 'elevation-popup';
3120
- }
3121
-
3122
- if (pop && pop._content) {
3123
- pop._content = decodeURI(pop._content);
3124
- p.bindTooltip(pop._content, {
3125
- direction: 'auto',
3126
- sticky: true,
3127
- opacity: 1,
3128
- className: 'elevation-tooltip'
3129
- }).openTooltip();
3130
- }
3131
- });
3132
- this.on("eletrack_download", function (e) {
3133
- if (e.downloadLink == 'modal' && typeof CustomEvent === "function") {
3134
- document.dispatchEvent(new CustomEvent("eletrack_download", {
3135
- detail: e
3136
- }));
3137
- } else if (e.downloadLink == 'link' || e.downloadLink === true) {
3138
- e.confirm();
3139
- }
3140
- });
3141
- this.on('eledata_loaded', function (e) {
3142
- var _this18 = this;
3143
-
3144
- var map = this._map;
3145
- var layer = e.layer;
3146
-
3147
- if (!map) {
3148
- console.warn("Undefined elevation map object");
3149
- return;
3150
- }
3151
-
3152
- map.once('layeradd', function (e) {
3153
- return _this18.options.autofitBounds && _this18.fitBounds(layer.getBounds());
3154
- });
3155
-
3156
- if (L.Browser.mobile) {
3157
- if (this.options.polyline) layer.addTo(map);
3158
- } else {
3159
- // leaflet-geometryutil
3160
- this.lazyLoad(this.__LGEOMUTIL).then(function () {
3161
- // leaflet-almostover
3162
- if (_this18.options.almostOver) {
3163
- _this18.lazyLoad(_this18.__LALMOSTOVER).then(function () {
3164
- map.addHandler('almostOver', L.Handler.AlmostOver);
3165
-
3166
- if (L.GeometryUtil && map.almostOver && map.almostOver.enabled()) {
3167
- map.almostOver.addLayer(layer);
3168
- map.on('almost:move', function (e) {
3169
- return _this18._mousemoveLayerHandler(e);
3170
- }).on('almost:out', function (e) {
3171
- return _this18._mouseoutHandler(e);
3172
- });
3173
- }
3174
- });
3175
- } // leaflet-distance-markers
3176
-
3177
-
3178
- if (_this18.options.distanceMarkers) {
3179
- _this18.lazyLoad(_this18.__LDISTANCEM).then(function () {
3180
- return _this18.options.polyline && layer.addTo(map);
3181
- });
3182
- } else {
3183
- if (_this18.options.polyline) layer.addTo(map);
3184
- }
3185
- });
3186
- }
3187
- }); // Basic canvas renderer support.
3188
-
3189
- var oldProto = L.Canvas.prototype._fillStroke;
3190
- var control = this;
3191
- L.Canvas.include({
3192
- _fillStroke: function _fillStroke(ctx, layer) {
3193
- if (control._layers.hasLayer(layer)) {
3194
- var theme = control.options.theme.replace('-theme', '');
3195
- var color = Colors[theme] || {};
3196
- var options = layer.options;
3197
- options.color = color.line || color.area || theme;
3198
- options.stroke = !!options.color;
3199
- oldProto.call(this, ctx, layer);
3200
-
3201
- if (options.stroke && options.weight !== 0) {
3202
- var oldVal = ctx.globalCompositeOperation || 'source-over';
3203
- ctx.globalCompositeOperation = 'destination-over';
3204
- ctx.strokeStyle = color.outline || '#FFF';
3205
- ctx.lineWidth = options.weight * 1.75;
3206
- ctx.stroke();
3207
- ctx.globalCompositeOperation = oldVal;
3208
- }
3209
- } else {
3210
- oldProto.call(this, ctx, layer);
3211
- }
3212
- }
3213
- }); // Partially fix: https://github.com/Raruto/leaflet-elevation/issues/81#issuecomment-713477050
3214
-
3215
- this.on('elechart_init', function () {
3216
- this.once('elechart_change elechart_hover', function (e) {
3217
- if (this._chartEnabled) {
3218
- this._chart._showDiagramIndicator(e.data, e.xCoord);
3219
-
3220
- this._chart._showDiagramIndicator(e.data, e.xCoord);
3221
- }
3222
-
3223
- this._updateMarker(e.data);
3224
- });
3225
- });
3226
- });
3227
3158
 
3228
3159
  Elevation.addInitHook(function () {
3229
3160
  var opts = this.options;
@@ -3904,7 +3835,19 @@
3904
3835
 
3905
3836
  return proto.call(null, string, data);
3906
3837
  };
3907
- })();
3838
+ })(); // Alias deprecated functions
3839
+
3840
+
3841
+ Elevation.addInitHook(function () {
3842
+ this.enableDragging = this.enableBrush;
3843
+ this.disableDragging = this.disableBrush;
3844
+ this.loadChart = this.addTo;
3845
+ this.loadData = this.load;
3846
+ this.loadGPX = this.load;
3847
+ this.loadGeoJSON = this.load;
3848
+ this.loadXML = this.load;
3849
+ this.loadFile = this.load;
3850
+ });
3908
3851
 
3909
3852
  L.control.elevation = function (options) {
3910
3853
  return new Elevation(options);