@raruto/leaflet-elevation 1.8.2 → 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,176 +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;
153
- var layer = L.geoJson(data, {
154
- distanceMarkers: distanceMarkers,
155
- style: function style(feature) {
156
- var style = L.extend({}, control.options.polyline);
157
-
158
- if (control.options.theme) {
159
- style.className += ' ' + control.options.theme;
160
- }
161
-
162
- return style;
163
- },
164
- pointToLayer: function pointToLayer(feature, latlng) {
165
- var _prop$desc, _prop$name, _prop$sym;
166
-
167
- if (!control.options.waypoints) return;
168
- var prop = feature.properties;
169
- var desc = (_prop$desc = prop.desc) !== null && _prop$desc !== void 0 ? _prop$desc : '';
170
- var name = (_prop$name = prop.name) !== null && _prop$name !== void 0 ? _prop$name : '';
171
- var sym = ((_prop$sym = prop.sym) !== null && _prop$sym !== void 0 ? _prop$sym : name).replace(' ', '-').replace('"', '').replace("'", '').toLowerCase(); // Handle chart waypoints (dots)
172
-
173
- if ([true, 'dots'].includes(control.options.waypoints)) {
174
- control._registerCheckPoint({
175
- latlng: latlng,
176
- label: [true, 'dots'].includes(wptLabels) ? name : ''
177
- }, true);
178
- } // Handle map waypoints (markers)
179
-
180
-
181
- if ([true, 'markers'].includes(control.options.waypoints) && wptIcons != false) {
182
- // generate and cache appropriate icon symbol
183
- if (!wptIcons.hasOwnProperty(sym)) {
184
- wptIcons[sym] = L.divIcon(L.extend({}, wptIcons[""].options, {
185
- html: '<i class="elevation-waypoint-icon ' + sym + '"></i>'
186
- }));
187
- }
188
-
189
- var marker = L.marker(latlng, {
190
- icon: wptIcons[sym]
191
- });
192
-
193
- if ([true, 'markers'].includes(wptLabels) && (name || desc)) {
194
- marker.bindPopup("<b>" + name + "</b>" + (desc.length > 0 ? '<br>' + desc : '')).openPopup();
195
- }
196
-
197
- control._addMarker(marker);
198
-
199
- control.fire('waypoint_added', {
200
- point: marker,
201
- element: latlng,
202
- properties: prop
203
- });
204
- return marker;
205
- }
206
- },
207
- onEachFeature: function onEachFeature(feature, layer) {
208
- if (feature.geometry && feature.geometry.type == 'Point') return; // Standard GeoJSON
209
- // control.addData(feature, layer); // NB uses "_addGeoJSONData"
210
- // Extended GeoJSON
211
-
212
- layer._latlngs.forEach(function (point, i, data) {
213
- // same properties as L.GPX layer
214
- point.meta = {
215
- time: null,
216
- ele: null,
217
- hr: null,
218
- cad: null,
219
- atemp: null
220
- };
221
- if ("alt" in point) point.meta.ele = point.alt;
222
-
223
- if (feature.properties) {
224
- var prop = feature.properties;
225
- 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));
226
- 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
227
- }
228
- });
229
-
230
- control.addData(layer); // NB uses "_addGPXData"
231
- // Postpone adding the distance markers (lazy: true)
232
-
233
- if (control.options.distanceMarkers && distanceMarkers.lazy) {
234
- layer.on('add remove', function (e) {
235
- var path = e.target;
236
-
237
- if (L.DistanceMarkers && path instanceof L.Polyline) {
238
- path[e.type + 'DistanceMarkers']();
239
- }
240
- });
241
- }
242
-
243
- control.track_info = L.extend({}, control.track_info, {
244
- type: "geojson",
245
- name: data.name
246
- });
247
- }
248
- });
249
-
250
- L.Control.Elevation._d3LazyLoader.then(function () {
251
- control._fireEvt("eledata_loaded", {
252
- data: data,
253
- layer: layer,
254
- name: control.track_info.name,
255
- track_info: control.track_info
256
- });
257
- });
258
-
259
- return layer;
260
- }
261
- /**
262
- * Check object type.
263
- */
264
-
265
- function isObject(item) {
266
- return item && _typeof(item) === 'object' && !Array.isArray(item);
267
- }
268
- /**
269
- * Check JSON object type.
270
- */
271
-
272
- function isJSONDoc(doc, lazy) {
273
- lazy = typeof lazy === "undefined" ? true : lazy;
274
-
275
- if (typeof doc === "string" && lazy) {
276
- doc = doc.trim();
277
- return doc.indexOf("{") == 0 || doc.indexOf("[") == 0;
278
- } else {
279
- try {
280
- JSON.parse(doc.toString());
281
- } catch (e) {
282
- if (_typeof(doc) === "object" && lazy) return true;
283
- console.warn(e);
284
- return false;
285
- }
286
-
287
- return true;
288
- }
289
- }
290
- /**
291
- * Check XML object type.
292
- */
293
-
294
- function isXMLDoc(doc, lazy) {
295
- lazy = typeof lazy === "undefined" ? true : lazy;
296
-
297
- if (typeof doc === "string" && lazy) {
298
- doc = doc.trim();
299
- return doc.indexOf("<") == 0;
300
- } else {
301
- var documentElement = (doc ? doc.ownerDocument || doc : 0).documentElement;
302
- return documentElement ? documentElement.nodeName !== "HTML" : false;
303
- }
304
- }
305
79
  /**
306
80
  * Generate download data event.
307
81
  */
@@ -340,40 +114,6 @@
340
114
  document.head.appendChild(tag);
341
115
  });
342
116
  }
343
- function lazyLoad(src, control) {
344
- if (!control.options.lazyLoadJS) return Promise.resolve();
345
- var Elevation = L.Control.Elevation;
346
- var loader = '';
347
- var condition = false;
348
-
349
- switch (src) {
350
- case control.__D3:
351
- loader = '_d3LazyLoader';
352
- condition = (typeof d3 === "undefined" ? "undefined" : _typeof(d3)) !== 'object';
353
- break;
354
-
355
- case control.__TOGEOJSON:
356
- loader = '_togeojsonLazyLoader';
357
- condition = (typeof toGeoJSON === "undefined" ? "undefined" : _typeof(toGeoJSON)) !== 'object';
358
- break;
359
-
360
- case control.__LGEOMUTIL:
361
- loader = '_geomutilLazyLoader';
362
- condition = _typeof(L.GeometryUtil) !== 'object';
363
-
364
- case control.__LALMOSTOVER:
365
- loader = '_almostoverLazyLoader';
366
- condition = typeof L.Handler.AlmostOver !== 'function ';
367
- break;
368
-
369
- case control.__LDISTANCEM:
370
- loader = '_distanceMarkersLazyLoader';
371
- condition = typeof L.DistanceMarkers !== 'function';
372
- break;
373
- }
374
-
375
- return Elevation[loader] = lazyLoader(src, condition, Elevation[loader]);
376
- }
377
117
  /**
378
118
  * Convert SVG Path into Path2D and then update canvas
379
119
  */
@@ -512,15 +252,9 @@
512
252
 
513
253
  var _ = /*#__PURE__*/Object.freeze({
514
254
  __proto__: null,
515
- deepMerge: deepMerge,
516
255
  formatTime: formatTime,
517
- GeoJSONLoader: GeoJSONLoader,
518
- isObject: isObject,
519
- isJSONDoc: isJSONDoc,
520
- isXMLDoc: isXMLDoc,
521
256
  saveFile: saveFile,
522
257
  lazyLoader: lazyLoader,
523
- lazyLoad: lazyLoad,
524
258
  drawCanvas: drawCanvas,
525
259
  clamp: clamp,
526
260
  addClass: addClass,
@@ -1299,6 +1033,8 @@
1299
1033
  _this4.zooming = true;
1300
1034
  _this4._scales.distance = _this4._x = e.transform.rescaleX(_this4._x); // calculate x scale at zoom level
1301
1035
 
1036
+ if (_this4._scales.time) _this4._scales.time = e.transform.rescaleX(_this4._scales.time); // calculate x scale at zoom level
1037
+
1302
1038
  _this4._resetDrag();
1303
1039
 
1304
1040
  if (e.sourceEvent && e.sourceEvent.type == "mousemove") {
@@ -1461,7 +1197,9 @@
1461
1197
  var opts = this.options;
1462
1198
  var scale = props.scale;
1463
1199
 
1464
- 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') {
1465
1203
  scale = L.extend({
1466
1204
  data: this._data,
1467
1205
  forceBounds: opts.forceAxisBounds
@@ -1796,6 +1534,22 @@
1796
1534
  }
1797
1535
  });
1798
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
+
1799
1553
  var Marker = L.Class.extend({
1800
1554
  initialize: function initialize(options) {
1801
1555
  this.options = options;
@@ -2039,7 +1793,7 @@
2039
1793
  __TOGEOJSON: 'https://unpkg.com/@tmcw/togeojson@4.3.0/dist/togeojson.umd.js',
2040
1794
  __LGEOMUTIL: 'https://unpkg.com/leaflet-geometryutil@0.9.3/src/leaflet.geometryutil.js',
2041
1795
  __LALMOSTOVER: 'https://unpkg.com/leaflet-almostover@1.0.1/src/leaflet.almostover.js',
2042
- __LDISTANCEM: 'https://unpkg.com/@raruto/leaflet-elevation@1.8.2/libs/leaflet-distance-marker.min.js',
1796
+ __LDISTANCEM: 'https://unpkg.com/@raruto/leaflet-elevation@1.8.5/libs/leaflet-distance-marker.min.js',
2043
1797
 
2044
1798
  /*
2045
1799
  * Add data to the diagram either from GPX or GeoJSON and update the axis domain and data
@@ -2199,86 +1953,74 @@
2199
1953
  this._markers = L.featureGroup();
2200
1954
  this._markedSegments = L.polyline([]);
2201
1955
  this._chartEnabled = true, this.track_info = {};
2202
- this.options = deepMerge({}, this.options, options);
1956
+ L.setOptions(this, options);
2203
1957
  if (this.options.followMarker) this._setMapView = L.Util.throttle(this._setMapView, 300, this);
2204
1958
  if (this.options.legend) this.options.margins.bottom += 30;
2205
1959
  if (this.options.theme) this.options.polylineSegments.className += ' ' + this.options.theme;
2206
1960
  if (this.options.wptIcons === true) this.options.wptIcons = Options.wptIcons;
1961
+ if (this.options.distanceMarkers === true) this.options.distanceMarkers = {
1962
+ lazy: true
1963
+ };
2207
1964
 
2208
1965
  this._markedSegments.setStyle(this.options.polylineSegments); // Leaflet canvas renderer colors
2209
1966
 
2210
1967
 
2211
- L.extend(Colors, this.options.colors || {});
1968
+ L.extend(Colors, this.options.colors || {}); // Various stuff
1969
+
1970
+ this._fixCanvasPaths();
1971
+
1972
+ this._fixTooltipSize();
2212
1973
  },
2213
1974
 
2214
1975
  /**
2215
1976
  * Javascript scripts downloader (lazy loader)
2216
1977
  */
2217
- lazyLoad: function lazyLoad$1(src) {
2218
- return lazyLoad(src, this);
2219
- },
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] : '';
2220
1981
 
2221
- /**
2222
- * Load elevation data (GPX, GeoJSON or KML).
2223
- */
2224
- load: function load(data) {
2225
- if (isXMLDoc(data)) {
2226
- this.loadXML(data);
2227
- } else if (isJSONDoc(data)) {
2228
- this.loadGeoJSON(data);
2229
- } else {
2230
- this.loadFile(data);
1982
+ if (!this.options.lazyLoadJS) {
1983
+ return Promise.resolve();
2231
1984
  }
2232
- },
2233
1985
 
2234
- /**
2235
- * Load data from a remote url.
2236
- */
2237
- loadFile: function loadFile(url) {
2238
- var _this3 = this;
1986
+ switch (src) {
1987
+ case this.__D3:
1988
+ loader = '_d3LazyLoader';
1989
+ condition = (typeof d3 === "undefined" ? "undefined" : _typeof(d3)) !== 'object';
1990
+ break;
2239
1991
 
2240
- fetch(url).then(function (response) {
2241
- return response.text();
2242
- }).then(function (data) {
2243
- _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;
2244
1996
 
2245
- _this3.load(data);
2246
- }).catch(function (err) {
2247
- return console.warn(err);
2248
- });
2249
- },
1997
+ case this.__LGEOMUTIL:
1998
+ loader = '_geomutilLazyLoader';
1999
+ condition = _typeof(L.GeometryUtil) !== 'object';
2000
+ break;
2250
2001
 
2251
- /**
2252
- * Load raw GeoJSON data.
2253
- */
2254
- loadGeoJSON: function loadGeoJSON(data) {
2255
- 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]);
2256
2014
  },
2257
2015
 
2258
2016
  /**
2259
- * Load raw XML data.
2017
+ * Load elevation data (GPX, GeoJSON or KML).
2260
2018
  */
2261
- loadXML: function loadXML(data) {
2262
- var _this4 = this;
2263
-
2264
- this.lazyLoad(this.__TOGEOJSON).then(function () {
2265
- var xml = new DOMParser().parseFromString(data, "text/xml");
2266
- var type = xml.documentElement.tagName.toLowerCase(); // "kml" or "gpx"
2267
-
2268
- if (!(type in toGeoJSON)) {
2269
- type = xml.documentElement.tagName == "TrainingCenterDatabase" ? 'tcx' : 'gpx';
2270
- }
2271
-
2272
- var geojson = toGeoJSON[type](xml);
2273
- var name = xml.getElementsByTagName('name');
2274
-
2275
- if (name[0]) {
2276
- geojson.name = name[0].innerHTML;
2277
- } else if (_this4._downloadURL) {
2278
- geojson.name = _this4._downloadURL.split('/').pop().split('#')[0].split('?')[0];
2279
- }
2019
+ load: function load(data) {
2020
+ var _this3 = this;
2280
2021
 
2281
- return _this4.loadGeoJSON(geojson, _this4);
2022
+ this._parseFromString(data).then(function (geojson) {
2023
+ return geojson ? _this3._loadLayer(geojson) : _this3._loadFile(data);
2282
2024
  });
2283
2025
  },
2284
2026
 
@@ -2287,38 +2029,36 @@
2287
2029
  * Called on control.addTo(map).
2288
2030
  */
2289
2031
  onAdd: function onAdd(map) {
2290
- var _this5 = this;
2032
+ var _this4 = this;
2291
2033
 
2292
2034
  this._map = map;
2293
2035
 
2294
- var container = this._container = create("div", "elevation-control elevation " + this.options.theme);
2295
-
2296
- if (!this.options.detached) {
2297
- addClass(container, 'leaflet-control');
2298
- }
2036
+ var container = this._container = create("div", "elevation-control elevation " + this.options.theme + " " + (this.options.detached ? '' : 'leaflet-control'));
2299
2037
 
2300
2038
  this.lazyLoad(this.__D3).then(function () {
2301
- _this5._initButton(container);
2039
+ _this4._initButton(container);
2040
+
2041
+ _this4._initChart(container);
2302
2042
 
2303
- _this5._initChart(container);
2043
+ _this4._initSummary(container);
2304
2044
 
2305
- _this5._initSummary(container);
2045
+ _this4._initMarker(map);
2306
2046
 
2307
- _this5._initMarker(map);
2047
+ _this4._initLayer(map);
2308
2048
 
2309
- _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);
2310
2050
 
2311
- 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);
2312
2052
 
2313
- on(map.getContainer(), 'mousewheel', _this5._resetDrag, _this5);
2053
+ on(map.getContainer(), 'touchstart', _this4._resetDrag, _this4);
2314
2054
 
2315
- on(map.getContainer(), 'touchstart', _this5._resetDrag, _this5);
2055
+ on(document, 'keydown', _this4._keydownHandler, _this4);
2316
2056
 
2317
- _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);
2318
2058
 
2319
- _this5._updateChart();
2059
+ _this4._updateChart();
2320
2060
 
2321
- _this5._updateSummary();
2061
+ _this4._updateSummary();
2322
2062
  });
2323
2063
  return container;
2324
2064
  },
@@ -2335,6 +2075,8 @@
2335
2075
 
2336
2076
  off(map.getContainer(), 'touchstart', this._resetDrag, this);
2337
2077
 
2078
+ off(document, 'keydown', this._keydownHandler, this);
2079
+
2338
2080
  this.off('eledata_added eledata_loaded', this._updateChart, this).off('eledata_added eledata_loaded', this._updateSummary, this);
2339
2081
  },
2340
2082
 
@@ -2363,7 +2105,7 @@
2363
2105
  * Parsing data either from GPX or GeoJSON and update the diagram data
2364
2106
  */
2365
2107
  _addData: function _addData(d) {
2366
- var _this6 = this;
2108
+ var _this5 = this;
2367
2109
 
2368
2110
  if (!d) {
2369
2111
  return;
@@ -2380,7 +2122,7 @@
2380
2122
 
2381
2123
  case 'MultiLineString':
2382
2124
  each(geom.coordinates, function (coords) {
2383
- return _this6._addGeoJSONData(coords);
2125
+ return _this5._addGeoJSONData(coords);
2384
2126
  });
2385
2127
 
2386
2128
  break;
@@ -2392,7 +2134,7 @@
2392
2134
 
2393
2135
  if (d.type === "FeatureCollection") {
2394
2136
  each(d.features, function (feature) {
2395
- return _this6._addData(feature);
2137
+ return _this5._addData(feature);
2396
2138
  });
2397
2139
  }
2398
2140
 
@@ -2405,14 +2147,14 @@
2405
2147
  * Parsing of GeoJSON data lines and their elevation in z-coordinate
2406
2148
  */
2407
2149
  _addGeoJSONData: function _addGeoJSONData(coords) {
2408
- var _this7 = this;
2150
+ var _this6 = this;
2409
2151
 
2410
2152
  each(coords, function (point) {
2411
- _this7._addPoint(point[1], point[0], point[2]);
2153
+ _this6._addPoint(point[1], point[0], point[2]);
2412
2154
 
2413
- _this7._fireEvt("elepoint_added", {
2155
+ _this6._fireEvt("elepoint_added", {
2414
2156
  point: point,
2415
- index: _this7._data.length - 1
2157
+ index: _this6._data.length - 1
2416
2158
  });
2417
2159
  });
2418
2160
 
@@ -2426,16 +2168,16 @@
2426
2168
  * Parsing function for GPX data and their elevation in z-coordinate
2427
2169
  */
2428
2170
  _addGPXData: function _addGPXData(coords) {
2429
- var _this8 = this;
2171
+ var _this7 = this;
2430
2172
 
2431
2173
  each(coords, function (point) {
2432
2174
  var _point$alt;
2433
2175
 
2434
- _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);
2435
2177
 
2436
- _this8._fireEvt("elepoint_added", {
2178
+ _this7._fireEvt("elepoint_added", {
2437
2179
  point: point,
2438
- index: _this8._data.length - 1
2180
+ index: _this7._data.length - 1
2439
2181
  });
2440
2182
  });
2441
2183
 
@@ -2467,11 +2209,68 @@
2467
2209
  });
2468
2210
  },
2469
2211
  _addLayer: function _addLayer(layer) {
2470
- 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
+ }
2471
2219
  },
2472
2220
  _addMarker: function _addMarker(marker) {
2473
2221
  if (marker) this._markers.addLayer(marker);
2474
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
+ },
2475
2274
 
2476
2275
  /**
2477
2276
  * Adds the control to the given "detached" div.
@@ -2490,8 +2289,7 @@
2490
2289
  replaceClass(eleDiv, 'leaflet-control', 'elevation-detached');
2491
2290
  }
2492
2291
 
2493
- this.eleDiv = eleDiv;
2494
- return this.eleDiv;
2292
+ return this.eleDiv = eleDiv;
2495
2293
  },
2496
2294
 
2497
2295
  /*
@@ -2508,6 +2306,58 @@
2508
2306
  replaceClass(this._container, 'elevation-collapsed', 'elevation-expanded');
2509
2307
  },
2510
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
+
2511
2361
  /*
2512
2362
  * Finds a data entry for the given LatLng
2513
2363
  */
@@ -2584,17 +2434,17 @@
2584
2434
  this._fireEvt("elechart_init");
2585
2435
  },
2586
2436
  _initLayer: function _initLayer() {
2587
- var _this9 = this;
2437
+ var _this11 = this;
2588
2438
 
2589
2439
  this._layers.on('layeradd layerremove', function (e) {
2590
2440
  var layer = e.layer;
2591
2441
  var node = layer.getElement && layer.getElement();
2592
2442
 
2593
- 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');
2594
2444
 
2595
- toggleEvent(layer, "mousemove", _this9._mousemoveLayerHandler.bind(_this9), e.type == 'layeradd');
2445
+ toggleEvent(layer, "mousemove", _this11._mousemoveLayerHandler.bind(_this11), e.type == 'layeradd');
2596
2446
 
2597
- toggleEvent(layer, "mouseout", _this9._mouseoutHandler.bind(_this9), e.type == 'layeradd');
2447
+ toggleEvent(layer, "mouseout", _this11._mouseoutHandler.bind(_this11), e.type == 'layeradd');
2598
2448
  });
2599
2449
  },
2600
2450
  _initMarker: function _initMarker(map) {
@@ -2621,19 +2471,10 @@
2621
2471
  * Inspired by L.Control.Layers
2622
2472
  */
2623
2473
  _initButton: function _initButton(container) {
2624
- //Makes this work on IE10 Touch devices by stopping it from firing a mouseout event when the touch is released
2625
- container.setAttribute('aria-haspopup', true);
2626
-
2627
- if (!this.options.detached) {
2474
+ if (L.Browser.mobile || !this.options.detached) {
2628
2475
  L.DomEvent.disableClickPropagation(container).disableScrollPropagation(container);
2629
2476
  }
2630
2477
 
2631
- if (L.Browser.mobile) {
2632
- on(container, 'click', L.DomEvent.stopPropagation);
2633
- }
2634
-
2635
- on(container, 'mousewheel', this._mousewheelHandler, this);
2636
-
2637
2478
  if (!this.options.detached) {
2638
2479
  var link = this._button = create('a', "elevation-toggle elevation-toggle-icon" + (this.options.autohide ? "" : " close-button"), {
2639
2480
  href: '#',
@@ -2655,17 +2496,160 @@
2655
2496
 
2656
2497
  on(link, 'focus', this._toggle, this);
2657
2498
 
2658
- this._map.on('click', this._collapse, this); // TODO: keyboard accessibility
2659
-
2499
+ this._map.on('click', this._collapse, this);
2660
2500
  }
2661
2501
  }
2662
2502
  },
2663
2503
  _initSummary: function _initSummary(container) {
2664
- var summary = this._summary = new Summary({
2504
+ this._summary = new Summary({
2665
2505
  summary: this.options.summary
2666
2506
  }, this);
2667
- d3.select(container).call(summary.render());
2668
- 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;
2669
2653
  },
2670
2654
  _dragendHandler: function _dragendHandler(e) {
2671
2655
  this._hideMarker();
@@ -2749,29 +2733,114 @@
2749
2733
  this._fireEvt("elechart_leave");
2750
2734
  },
2751
2735
 
2752
- /*
2753
- * Handles the mouesewheel over the chart.
2736
+ /**
2737
+ * Simple GeoJSON Parser
2754
2738
  */
2755
- _mousewheelHandler: function _mousewheelHandler(e) {
2756
- if (this._map.gestureHandling && this._map.gestureHandling._enabled) return;
2739
+ _parseFromGeoJSONString: function _parseFromGeoJSONString(data) {
2740
+ try {
2741
+ return JSON.parse(data);
2742
+ } catch (e) {}
2743
+ },
2757
2744
 
2758
- var ll = this._marker.getLatLng() || this._map.getCenter();
2745
+ /**
2746
+ * Attempt to parse raw response data (GeoJSON or XML > GeoJSON)
2747
+ */
2748
+ _parseFromString: function _parseFromString(data) {
2749
+ var _this13 = this;
2759
2750
 
2760
- var z = this._map.getZoom() + Math.sign(e.deltaY);
2751
+ return new Promise(function (resolve) {
2752
+ return _this13.lazyLoad(_this13.__TOGEOJSON).then(function () {
2753
+ var geojson;
2761
2754
 
2762
- this._resetDrag();
2755
+ try {
2756
+ geojson = _this13._parseFromXMLString(data.trim());
2757
+ } catch (e) {
2758
+ geojson = _this13._parseFromGeoJSONString(data.toString());
2759
+ }
2760
+
2761
+ if (geojson) {
2762
+ geojson = _this13._prepareMultiLineStrings(geojson);
2763
+ geojson = _this13._prepareAdditionalProperties(geojson);
2764
+ }
2765
+
2766
+ resolve(geojson);
2767
+ });
2768
+ });
2769
+ },
2770
+
2771
+ /**
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"
2763
2781
 
2764
- this._map.flyTo(ll, z);
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;
2765
2797
  },
2766
2798
 
2767
2799
  /**
2768
- * Add a waypoint marker to the diagram
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
2769
2838
  */
2770
2839
  _registerCheckPoint: function _registerCheckPoint(props) {
2771
- var _this10 = this;
2840
+ var _this14 = this;
2772
2841
 
2773
2842
  this.on("elechart_updated", function () {
2774
- return _this10._chart._registerCheckPoint(props);
2843
+ return _this14._chart._registerCheckPoint(props);
2775
2844
  });
2776
2845
  },
2777
2846
 
@@ -2779,10 +2848,10 @@
2779
2848
  * Add chart profile to diagram
2780
2849
  */
2781
2850
  _registerAreaPath: function _registerAreaPath(props) {
2782
- var _this11 = this;
2851
+ var _this15 = this;
2783
2852
 
2784
2853
  this.on("elechart_init", function () {
2785
- return _this11._chart._registerAreaPath(props);
2854
+ return _this15._chart._registerAreaPath(props);
2786
2855
  });
2787
2856
  },
2788
2857
 
@@ -2790,10 +2859,10 @@
2790
2859
  * Add chart grid to diagram
2791
2860
  */
2792
2861
  _registerAxisGrid: function _registerAxisGrid(props) {
2793
- var _this12 = this;
2862
+ var _this16 = this;
2794
2863
 
2795
2864
  this.on("elechart_axis", function () {
2796
- return _this12._chart._registerAxisGrid(props);
2865
+ return _this16._chart._registerAxisGrid(props);
2797
2866
  });
2798
2867
  },
2799
2868
 
@@ -2801,10 +2870,10 @@
2801
2870
  * Add chart axis to diagram
2802
2871
  */
2803
2872
  _registerAxisScale: function _registerAxisScale(props) {
2804
- var _this13 = this;
2873
+ var _this17 = this;
2805
2874
 
2806
2875
  this.on("elechart_axis", function () {
2807
- return _this13._chart._registerAxisScale(props);
2876
+ return _this17._chart._registerAxisScale(props);
2808
2877
  });
2809
2878
  },
2810
2879
 
@@ -2812,14 +2881,14 @@
2812
2881
  * Add chart or marker tooltip info
2813
2882
  */
2814
2883
  _registerTooltip: function _registerTooltip(props) {
2815
- var _this14 = this;
2884
+ var _this18 = this;
2816
2885
 
2817
2886
  if (props.chart) {
2818
2887
  var label = L.extend({}, props, {
2819
2888
  value: props.chart
2820
2889
  });
2821
2890
  this.on("elechart_init", function () {
2822
- return _this14._chart._registerTooltip(label);
2891
+ return _this18._chart._registerTooltip(label);
2823
2892
  });
2824
2893
  }
2825
2894
 
@@ -2829,7 +2898,7 @@
2829
2898
  });
2830
2899
 
2831
2900
  this.on("elechart_marker", function () {
2832
- return _this14._marker._registerTooltip(_label);
2901
+ return _this18._marker._registerTooltip(_label);
2833
2902
  });
2834
2903
  }
2835
2904
  },
@@ -2838,10 +2907,10 @@
2838
2907
  * Add summary info to diagram
2839
2908
  */
2840
2909
  _registerSummary: function _registerSummary(props) {
2841
- var _this15 = this;
2910
+ var _this19 = this;
2842
2911
 
2843
2912
  this.on('elechart_summary', function () {
2844
- return _this15._summary._registerSummary(props);
2913
+ return _this19._summary._registerSummary(props);
2845
2914
  });
2846
2915
  },
2847
2916
 
@@ -2946,7 +3015,7 @@
2946
3015
  * Toggle chart data on legend click
2947
3016
  */
2948
3017
  _toggleChartHandler: function _toggleChartHandler(e) {
2949
- var _this16 = this;
3018
+ var _this20 = this;
2950
3019
 
2951
3020
  var path = e.path,
2952
3021
  name = e.name,
@@ -2956,7 +3025,7 @@
2956
3025
  this._layers.eachLayer(function (layer) {
2957
3026
  var node = layer.getElement && layer.getElement();
2958
3027
 
2959
- toggleClass(node, _this16.options.polyline.className + ' ' + _this16.options.theme, _this16._chartEnabled);
3028
+ toggleClass(node, _this20.options.polyline.className + ' ' + _this20.options.theme, _this20._chartEnabled);
2960
3029
  }); // toggle option value (eg. altitude = { 'disabled' || 'disabled' })
2961
3030
 
2962
3031
 
@@ -3030,7 +3099,7 @@
3030
3099
  * Update chart summary.
3031
3100
  */
3032
3101
  _updateSummary: function _updateSummary() {
3033
- var _this17 = this;
3102
+ var _this21 = this;
3034
3103
 
3035
3104
  this._summary.reset();
3036
3105
 
@@ -3040,14 +3109,22 @@
3040
3109
 
3041
3110
  if (this.options.downloadLink && this._downloadURL) {
3042
3111
  // TODO: generate dynamically file content instead of using static file urls.
3043
- 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>';
3044
3113
 
3045
- select('.download a', this.summaryDiv).onclick = function (e) {
3114
+ select('.download a', this._summary._container).onclick = function (e) {
3046
3115
  e.preventDefault();
3047
3116
 
3048
- _this17._fireEvt('eletrack_download', {
3049
- downloadLink: _this17.options.downloadLink,
3050
- 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)
3051
3128
  });
3052
3129
  };
3053
3130
  }
@@ -3078,130 +3155,6 @@
3078
3155
  return this.__yTicks || Math.round(this._height() / 30);
3079
3156
  }
3080
3157
  });
3081
- /**
3082
- * Attach here some useful elevation hooks.
3083
- */
3084
-
3085
- Elevation.addInitHook(function () {
3086
- // Alias deprecated functions
3087
- this.enableDragging = this.enableBrush;
3088
- this.disableDragging = this.disableBrush;
3089
- this.loadChart = this.addTo;
3090
- this.loadData = this.load;
3091
- this.loadGPX = this.loadXML;
3092
- this.on('waypoint_added', function (e) {
3093
- var p = e.point,
3094
- pop = p._popup;
3095
-
3096
- if (pop) {
3097
- pop.options.className = 'elevation-popup';
3098
- }
3099
-
3100
- if (pop && pop._content) {
3101
- pop._content = decodeURI(pop._content);
3102
- p.bindTooltip(pop._content, {
3103
- direction: 'auto',
3104
- sticky: true,
3105
- opacity: 1,
3106
- className: 'elevation-tooltip'
3107
- }).openTooltip();
3108
- }
3109
- });
3110
- this.on("eletrack_download", function (e) {
3111
- if (e.downloadLink == 'modal' && typeof CustomEvent === "function") {
3112
- document.dispatchEvent(new CustomEvent("eletrack_download", {
3113
- detail: e
3114
- }));
3115
- } else if (e.downloadLink == 'link' || e.downloadLink === true) {
3116
- e.confirm();
3117
- }
3118
- });
3119
- this.on('eledata_loaded', function (e) {
3120
- var _this18 = this;
3121
-
3122
- var map = this._map;
3123
- var layer = e.layer;
3124
-
3125
- if (!map) {
3126
- console.warn("Undefined elevation map object");
3127
- return;
3128
- }
3129
-
3130
- map.once('layeradd', function (e) {
3131
- return _this18.options.autofitBounds && _this18.fitBounds(layer.getBounds());
3132
- });
3133
-
3134
- if (L.Browser.mobile) {
3135
- if (this.options.polyline) layer.addTo(map);
3136
- } else {
3137
- // leaflet-geometryutil
3138
- this.lazyLoad(this.__LGEOMUTIL).then(function () {
3139
- // leaflet-almostover
3140
- if (_this18.options.almostOver) {
3141
- _this18.lazyLoad(_this18.__LALMOSTOVER).then(function () {
3142
- map.addHandler('almostOver', L.Handler.AlmostOver);
3143
-
3144
- if (L.GeometryUtil && map.almostOver && map.almostOver.enabled()) {
3145
- map.almostOver.addLayer(layer);
3146
- map.on('almost:move', function (e) {
3147
- return _this18._mousemoveLayerHandler(e);
3148
- }).on('almost:out', function (e) {
3149
- return _this18._mouseoutHandler(e);
3150
- });
3151
- }
3152
- });
3153
- } // leaflet-distance-markers
3154
-
3155
-
3156
- if (_this18.options.distanceMarkers) {
3157
- _this18.lazyLoad(_this18.__LDISTANCEM).then(function () {
3158
- return _this18.options.polyline && layer.addTo(map);
3159
- });
3160
- } else {
3161
- if (_this18.options.polyline) layer.addTo(map);
3162
- }
3163
- });
3164
- }
3165
- }); // Basic canvas renderer support.
3166
-
3167
- var oldProto = L.Canvas.prototype._fillStroke;
3168
- var control = this;
3169
- L.Canvas.include({
3170
- _fillStroke: function _fillStroke(ctx, layer) {
3171
- if (control._layers.hasLayer(layer)) {
3172
- var theme = control.options.theme.replace('-theme', '');
3173
- var color = Colors[theme] || {};
3174
- var options = layer.options;
3175
- options.color = color.line || color.area || theme;
3176
- options.stroke = !!options.color;
3177
- oldProto.call(this, ctx, layer);
3178
-
3179
- if (options.stroke && options.weight !== 0) {
3180
- var oldVal = ctx.globalCompositeOperation || 'source-over';
3181
- ctx.globalCompositeOperation = 'destination-over';
3182
- ctx.strokeStyle = color.outline || '#FFF';
3183
- ctx.lineWidth = options.weight * 1.75;
3184
- ctx.stroke();
3185
- ctx.globalCompositeOperation = oldVal;
3186
- }
3187
- } else {
3188
- oldProto.call(this, ctx, layer);
3189
- }
3190
- }
3191
- }); // Partially fix: https://github.com/Raruto/leaflet-elevation/issues/81#issuecomment-713477050
3192
-
3193
- this.on('elechart_init', function () {
3194
- this.once('elechart_change elechart_hover', function (e) {
3195
- if (this._chartEnabled) {
3196
- this._chart._showDiagramIndicator(e.data, e.xCoord);
3197
-
3198
- this._chart._showDiagramIndicator(e.data, e.xCoord);
3199
- }
3200
-
3201
- this._updateMarker(e.data);
3202
- });
3203
- });
3204
- });
3205
3158
 
3206
3159
  Elevation.addInitHook(function () {
3207
3160
  var opts = this.options;
@@ -3882,7 +3835,19 @@
3882
3835
 
3883
3836
  return proto.call(null, string, data);
3884
3837
  };
3885
- })();
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
+ });
3886
3851
 
3887
3852
  L.control.elevation = function (options) {
3888
3853
  return new Elevation(options);