@raruto/leaflet-elevation 1.8.4 → 1.8.7

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;
@@ -2058,10 +1790,10 @@
2058
1790
  __mileFactor: 0.621371,
2059
1791
  __footFactor: 3.28084,
2060
1792
  __D3: 'https://unpkg.com/d3@6.5.0/dist/d3.min.js',
2061
- __TOGEOJSON: 'https://unpkg.com/@tmcw/togeojson@4.3.0/dist/togeojson.umd.js',
1793
+ __TOGEOJSON: 'https://unpkg.com/@tmcw/togeojson@4.5.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.7/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,11 +2105,15 @@
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;
2392
2112
  }
2113
+ /**
2114
+ * Standard GeoJSON --> doesn't handle "time", "heart", …
2115
+ */
2116
+
2393
2117
 
2394
2118
  var geom = d.geometry;
2395
2119
 
@@ -2402,7 +2126,7 @@
2402
2126
 
2403
2127
  case 'MultiLineString':
2404
2128
  each(geom.coordinates, function (coords) {
2405
- return _this6._addGeoJSONData(coords);
2129
+ return _this5._addGeoJSONData(coords);
2406
2130
  });
2407
2131
 
2408
2132
  break;
@@ -2414,50 +2138,50 @@
2414
2138
 
2415
2139
  if (d.type === "FeatureCollection") {
2416
2140
  each(d.features, function (feature) {
2417
- return _this6._addData(feature);
2141
+ return _this5._addData(feature);
2418
2142
  });
2419
2143
  }
2144
+ /**
2145
+ * Extended GeoJSON --> rely on leaflet implementation
2146
+ */
2147
+
2420
2148
 
2421
2149
  if (d._latlngs) {
2422
- this._addGPXData(d._latlngs);
2150
+ this._addGeoJSONData(d._latlngs, d.feature && d.feature.properties);
2423
2151
  }
2424
2152
  },
2425
2153
 
2426
2154
  /*
2427
2155
  * Parsing of GeoJSON data lines and their elevation in z-coordinate
2428
2156
  */
2429
- _addGeoJSONData: function _addGeoJSONData(coords) {
2430
- var _this7 = this;
2431
-
2432
- each(coords, function (point) {
2433
- _this7._addPoint(point[1], point[0], point[2]);
2157
+ _addGeoJSONData: function _addGeoJSONData(coords, properties) {
2158
+ var _this6 = this;
2434
2159
 
2435
- _this7._fireEvt("elepoint_added", {
2436
- point: point,
2437
- index: _this7._data.length - 1
2438
- });
2439
- });
2160
+ coords.forEach(function (point, i) {
2161
+ var _point$meta, _point$lat, _point$lng, _ref, _point$alt;
2440
2162
 
2441
- this._fireEvt("eletrack_added", {
2442
- coords: coords,
2443
- index: this._data.length - 1
2444
- });
2445
- },
2163
+ // Inspired by L.GPX layer properties
2164
+ point.meta = (_point$meta = point.meta) !== null && _point$meta !== void 0 ? _point$meta : {
2165
+ time: null,
2166
+ ele: null,
2167
+ hr: null,
2168
+ cad: null,
2169
+ atemp: null
2170
+ }; // "alt" property is generated inside "leaflet"
2446
2171
 
2447
- /*
2448
- * Parsing function for GPX data and their elevation in z-coordinate
2449
- */
2450
- _addGPXData: function _addGPXData(coords) {
2451
- var _this8 = this;
2172
+ if ("alt" in point) point.meta.ele = point.alt; // "coordinateProperties" property is generated inside "@tmcw/toGeoJSON"
2452
2173
 
2453
- each(coords, function (point) {
2454
- var _point$alt;
2174
+ if (properties.coordinateProperties) {
2175
+ var props = properties.coordinateProperties;
2176
+ if ("times" in props) point.meta.time = new Date(Date.parse(props.times[i]));
2177
+ if ("heart" in props) point.meta.hr = parseInt(props.heart[i]); // TODO: ask to "@tmcw/toGeoJSON" for "cadence" and "temperature" implementation
2178
+ }
2455
2179
 
2456
- _this8._addPoint(point.lat, point.lng, (_point$alt = point.alt) !== null && _point$alt !== void 0 ? _point$alt : point.meta.ele);
2180
+ _this6._addPoint((_point$lat = point.lat) !== null && _point$lat !== void 0 ? _point$lat : point[1], (_point$lng = point.lng) !== null && _point$lng !== void 0 ? _point$lng : point[0], (_ref = (_point$alt = point.alt) !== null && _point$alt !== void 0 ? _point$alt : point.meta.ele) !== null && _ref !== void 0 ? _ref : point[2]);
2457
2181
 
2458
- _this8._fireEvt("elepoint_added", {
2182
+ _this6._fireEvt("elepoint_added", {
2459
2183
  point: point,
2460
- index: _this8._data.length - 1
2184
+ index: _this6._data.length - 1
2461
2185
  });
2462
2186
  });
2463
2187
 
@@ -2472,9 +2196,9 @@
2472
2196
  */
2473
2197
  _addPoint: function _addPoint(x, y, z) {
2474
2198
  if (this.options.reverseCoords) {
2475
- var _ref = [y, x];
2476
- x = _ref[0];
2477
- y = _ref[1];
2199
+ var _ref2 = [y, x];
2200
+ x = _ref2[0];
2201
+ y = _ref2[1];
2478
2202
  }
2479
2203
 
2480
2204
  this._data.push({
@@ -2489,11 +2213,76 @@
2489
2213
  });
2490
2214
  },
2491
2215
  _addLayer: function _addLayer(layer) {
2492
- if (layer) this._layers.addLayer(layer);
2216
+ if (layer) this._layers.addLayer(layer); // Postpone adding the distance markers (lazy: true)
2217
+
2218
+ if (layer && this.options.distanceMarkers && this.options.distanceMarkers.lazy) {
2219
+ layer.on('add remove', function (e) {
2220
+ return L.DistanceMarkers && e.target instanceof L.Polyline && e.target[e.type + 'DistanceMarkers']();
2221
+ });
2222
+ }
2493
2223
  },
2494
2224
  _addMarker: function _addMarker(marker) {
2495
2225
  if (marker) this._markers.addLayer(marker);
2496
2226
  },
2227
+ _bindPopup: function _bindPopup(marker) {
2228
+ var popup = marker._popup;
2229
+
2230
+ if (popup) {
2231
+ popup.options.className = 'elevation-popup';
2232
+
2233
+ if (popup._content) {
2234
+ popup._content = decodeURI(popup._content);
2235
+ popup.bindTooltip(popup._content, {
2236
+ direction: 'auto',
2237
+ sticky: true,
2238
+ opacity: 1,
2239
+ className: 'elevation-tooltip'
2240
+ }).openTooltip();
2241
+ }
2242
+ }
2243
+ },
2244
+
2245
+ /**
2246
+ * Initialize "L.AlmostOver" integration
2247
+ */
2248
+ _initAlmostOverHandler: function _initAlmostOverHandler(map, layer) {
2249
+ var _this7 = this;
2250
+
2251
+ if (!map || !this.options.almostOver) return;
2252
+ this.lazyLoad(this.__LGEOMUTIL).then(function () {
2253
+ return _this7.lazyLoad(_this7.__LALMOSTOVER);
2254
+ }).then(function () {
2255
+ map.addHandler('almostOver', L.Handler.AlmostOver);
2256
+
2257
+ if (L.GeometryUtil && map.almostOver && map.almostOver.enabled()) {
2258
+ map.almostOver.addLayer(layer);
2259
+ map.on('almost:move', function (e) {
2260
+ return _this7._mousemoveLayerHandler(e);
2261
+ }).on('almost:out', function (e) {
2262
+ return _this7._mouseoutHandler(e);
2263
+ });
2264
+ }
2265
+ });
2266
+ },
2267
+
2268
+ /**
2269
+ * Initialize "L.DistanceMarkers" integration
2270
+ */
2271
+ _initDistanceMarkers: function _initDistanceMarkers(map, layer) {
2272
+ var _this8 = this;
2273
+
2274
+ if (!map) return;
2275
+
2276
+ if (this.options.distanceMarkers) {
2277
+ this.lazyLoad(this.__LGEOMUTIL).then(function () {
2278
+ return _this8.lazyLoad(_this8.__LDISTANCEM);
2279
+ }).then(function () {
2280
+ return _this8.options.polyline && layer.addTo(map);
2281
+ });
2282
+ } else if (this.options.polyline) {
2283
+ layer.addTo(map);
2284
+ }
2285
+ },
2497
2286
 
2498
2287
  /**
2499
2288
  * Adds the control to the given "detached" div.
@@ -2512,8 +2301,30 @@
2512
2301
  replaceClass(eleDiv, 'leaflet-control', 'elevation-detached');
2513
2302
  }
2514
2303
 
2515
- this.eleDiv = eleDiv;
2516
- return this.eleDiv;
2304
+ return this.eleDiv = eleDiv;
2305
+ },
2306
+
2307
+ /**
2308
+ * Initialize "L.AlmostOver" and "L.DistanceMarkers"
2309
+ */
2310
+ _initMapIntegrations: function _initMapIntegrations(control, layer) {
2311
+ var map = control._map;
2312
+
2313
+ if (control._map) {
2314
+ map.once('layeradd', function (e) {
2315
+ return control.options.autofitBounds && control.fitBounds(layer.getBounds());
2316
+ });
2317
+
2318
+ if (!L.Browser.mobile) {
2319
+ control._initAlmostOverHandler(map, layer);
2320
+
2321
+ control._initDistanceMarkers(map, layer);
2322
+ } else if (control.options.polyline) {
2323
+ layer.addTo(map);
2324
+ }
2325
+ } else {
2326
+ console.warn("Undefined elevation map object");
2327
+ }
2517
2328
  },
2518
2329
 
2519
2330
  /*
@@ -2530,6 +2341,58 @@
2530
2341
  replaceClass(this._container, 'elevation-collapsed', 'elevation-expanded');
2531
2342
  },
2532
2343
 
2344
+ /**
2345
+ * Add some basic colors to leaflet canvas renderer (preferCanvas: true).
2346
+ */
2347
+ _fixCanvasPaths: function _fixCanvasPaths() {
2348
+ var oldProto = L.Canvas.prototype._fillStroke;
2349
+ var control = this;
2350
+ L.Canvas.include({
2351
+ _fillStroke: function _fillStroke(ctx, layer) {
2352
+ if (control._layers.hasLayer(layer)) {
2353
+ var theme = control.options.theme.replace('-theme', '');
2354
+ var color = Colors[theme] || {};
2355
+ var options = layer.options;
2356
+ options.color = color.line || color.area || theme;
2357
+ options.stroke = !!options.color;
2358
+ oldProto.call(this, ctx, layer);
2359
+
2360
+ if (options.stroke && options.weight !== 0) {
2361
+ var oldVal = ctx.globalCompositeOperation || 'source-over';
2362
+ ctx.globalCompositeOperation = 'destination-over';
2363
+ ctx.strokeStyle = color.outline || '#FFF';
2364
+ ctx.lineWidth = options.weight * 1.75;
2365
+ ctx.stroke();
2366
+ ctx.globalCompositeOperation = oldVal;
2367
+ }
2368
+ } else {
2369
+ oldProto.call(this, ctx, layer);
2370
+ }
2371
+ }
2372
+ });
2373
+ },
2374
+
2375
+ /**
2376
+ * Partial fix for initial tooltip size
2377
+ *
2378
+ * @link https://github.com/Raruto/leaflet-elevation/issues/81#issuecomment-713477050
2379
+ */
2380
+ _fixTooltipSize: function _fixTooltipSize() {
2381
+ var _this9 = this;
2382
+
2383
+ this.on('elechart_init', function () {
2384
+ return _this9.once('elechart_change elechart_hover', function (e) {
2385
+ if (_this9._chartEnabled) {
2386
+ _this9._chart._showDiagramIndicator(e.data, e.xCoord);
2387
+
2388
+ _this9._chart._showDiagramIndicator(e.data, e.xCoord);
2389
+ }
2390
+
2391
+ _this9._updateMarker(e.data);
2392
+ });
2393
+ });
2394
+ },
2395
+
2533
2396
  /*
2534
2397
  * Finds a data entry for the given LatLng
2535
2398
  */
@@ -2606,17 +2469,17 @@
2606
2469
  this._fireEvt("elechart_init");
2607
2470
  },
2608
2471
  _initLayer: function _initLayer() {
2609
- var _this9 = this;
2472
+ var _this10 = this;
2610
2473
 
2611
2474
  this._layers.on('layeradd layerremove', function (e) {
2612
2475
  var layer = e.layer;
2613
2476
  var node = layer.getElement && layer.getElement();
2614
2477
 
2615
- toggleClass(node, _this9.options.polyline.className + ' ' + _this9.options.theme, e.type == 'layeradd');
2478
+ toggleClass(node, _this10.options.polyline.className + ' ' + _this10.options.theme, e.type == 'layeradd');
2616
2479
 
2617
- toggleEvent(layer, "mousemove", _this9._mousemoveLayerHandler.bind(_this9), e.type == 'layeradd');
2480
+ toggleEvent(layer, "mousemove", _this10._mousemoveLayerHandler.bind(_this10), e.type == 'layeradd');
2618
2481
 
2619
- toggleEvent(layer, "mouseout", _this9._mouseoutHandler.bind(_this9), e.type == 'layeradd');
2482
+ toggleEvent(layer, "mouseout", _this10._mouseoutHandler.bind(_this10), e.type == 'layeradd');
2620
2483
  });
2621
2484
  },
2622
2485
  _initMarker: function _initMarker(map) {
@@ -2643,19 +2506,10 @@
2643
2506
  * Inspired by L.Control.Layers
2644
2507
  */
2645
2508
  _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) {
2509
+ if (L.Browser.mobile || !this.options.detached) {
2650
2510
  L.DomEvent.disableClickPropagation(container).disableScrollPropagation(container);
2651
2511
  }
2652
2512
 
2653
- if (L.Browser.mobile) {
2654
- on(container, 'click', L.DomEvent.stopPropagation);
2655
- }
2656
-
2657
- on(container, 'mousewheel', this._mousewheelHandler, this);
2658
-
2659
2513
  if (!this.options.detached) {
2660
2514
  var link = this._button = create('a', "elevation-toggle elevation-toggle-icon" + (this.options.autohide ? "" : " close-button"), {
2661
2515
  href: '#',
@@ -2677,17 +2531,125 @@
2677
2531
 
2678
2532
  on(link, 'focus', this._toggle, this);
2679
2533
 
2680
- this._map.on('click', this._collapse, this); // TODO: keyboard accessibility
2681
-
2534
+ this._map.on('click', this._collapse, this);
2682
2535
  }
2683
2536
  }
2684
2537
  },
2685
2538
  _initSummary: function _initSummary(container) {
2686
- var summary = this._summary = new Summary({
2539
+ this._summary = new Summary({
2687
2540
  summary: this.options.summary
2688
2541
  }, this);
2689
- d3.select(container).call(summary.render());
2690
- this.summaryDiv = this._summary._container;
2542
+ d3.select(container).call(this._summary.render());
2543
+ },
2544
+ _keydownHandler: function _keydownHandler(e) {
2545
+ if (!this.options.detached && e.key === "Escape") {
2546
+ this._collapse();
2547
+ }
2548
+ },
2549
+
2550
+ /**
2551
+ * Retrieve data from a remote url (HTTP).
2552
+ */
2553
+ _loadFile: function _loadFile(url) {
2554
+ var _this11 = this;
2555
+
2556
+ fetch(url).then(function (response) {
2557
+ return response.text();
2558
+ }).then(function (data) {
2559
+ _this11._downloadURL = url; // TODO: handle multiple urls?
2560
+
2561
+ _this11._parseFromString(data).then(function (geojson) {
2562
+ return geojson && _this11._loadLayer(geojson);
2563
+ });
2564
+ }).catch(function (err) {
2565
+ return console.warn(err);
2566
+ });
2567
+ },
2568
+
2569
+ /**
2570
+ * Simple GeoJSON data loader (L.GeoJSON).
2571
+ */
2572
+ _loadLayer: function _loadLayer(geojson) {
2573
+ var control = this;
2574
+ var _control$options = control.options,
2575
+ wptIcons = _control$options.wptIcons,
2576
+ wptLabels = _control$options.wptLabels;
2577
+ var layer = L.geoJson(geojson, {
2578
+ distanceMarkers: control.options.distanceMarkers,
2579
+ style: function style(feature) {
2580
+ var style = L.extend({}, control.options.polyline);
2581
+
2582
+ if (control.options.theme) {
2583
+ style.className += ' ' + control.options.theme;
2584
+ }
2585
+
2586
+ return style;
2587
+ },
2588
+ pointToLayer: function pointToLayer(feature, latlng) {
2589
+ var _prop$desc, _prop$name, _prop$sym;
2590
+
2591
+ if (!control.options.waypoints) return;
2592
+ var prop = feature.properties;
2593
+ var desc = (_prop$desc = prop.desc) !== null && _prop$desc !== void 0 ? _prop$desc : '';
2594
+ var name = (_prop$name = prop.name) !== null && _prop$name !== void 0 ? _prop$name : '';
2595
+ var sym = ((_prop$sym = prop.sym) !== null && _prop$sym !== void 0 ? _prop$sym : name).replace(' ', '-').replace('"', '').replace("'", '').toLowerCase(); // Handle chart waypoints (dots)
2596
+
2597
+ if ([true, 'dots'].includes(control.options.waypoints)) {
2598
+ control._registerCheckPoint({
2599
+ latlng: latlng,
2600
+ label: [true, 'dots'].includes(wptLabels) ? name : ''
2601
+ });
2602
+ } // Handle map waypoints (markers)
2603
+
2604
+
2605
+ if ([true, 'markers'].includes(control.options.waypoints) && wptIcons != false) {
2606
+ // generate and cache appropriate icon symbol
2607
+ if (!wptIcons.hasOwnProperty(sym)) {
2608
+ wptIcons[sym] = L.divIcon(L.extend({}, wptIcons[""].options, {
2609
+ html: '<i class="elevation-waypoint-icon ' + sym + '"></i>'
2610
+ }));
2611
+ }
2612
+
2613
+ var marker = L.marker(latlng, {
2614
+ icon: wptIcons[sym]
2615
+ });
2616
+
2617
+ if ([true, 'markers'].includes(wptLabels) && (name || desc)) {
2618
+ marker.bindPopup("<b>" + name + "</b>" + (desc.length > 0 ? '<br>' + desc : '')).openPopup();
2619
+ }
2620
+
2621
+ control._addMarker(marker);
2622
+
2623
+ control._bindPopup(marker);
2624
+
2625
+ control.fire('waypoint_added', {
2626
+ point: marker,
2627
+ element: latlng,
2628
+ properties: prop
2629
+ });
2630
+ return marker;
2631
+ }
2632
+ },
2633
+ onEachFeature: function onEachFeature(feature, layer) {
2634
+ if (feature.geometry && feature.geometry.type != 'Point') {
2635
+ control.addData(layer);
2636
+ control.track_info = L.extend({}, control.track_info, {
2637
+ name: geojson.name
2638
+ });
2639
+ }
2640
+ }
2641
+ });
2642
+ control.lazyLoad(control.__D3).then(function () {
2643
+ control._initMapIntegrations(control, layer);
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,116 @@
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 _this12 = this;
2779
2750
 
2780
- var ll = this._marker.getLatLng() || this._map.getCenter();
2751
+ return new Promise(function (resolve) {
2752
+ return _this12.lazyLoad(_this12.__TOGEOJSON).then(function () {
2753
+ var geojson;
2781
2754
 
2782
- var z = this._map.getZoom() + Math.sign(e.deltaY);
2755
+ try {
2756
+ geojson = _this12._parseFromXMLString(data.trim());
2757
+ } catch (e) {
2758
+ geojson = _this12._parseFromGeoJSONString(data.toString());
2759
+ }
2783
2760
 
2784
- this._resetDrag();
2761
+ if (geojson) {
2762
+ geojson = _this12._prepareMultiLineStrings(geojson);
2763
+ geojson = _this12._prepareAdditionalProperties(geojson);
2764
+ }
2785
2765
 
2786
- this._map.flyTo(ll, z);
2766
+ resolve(geojson);
2767
+ });
2768
+ });
2769
+ },
2770
+
2771
+ /**
2772
+ * Simple XML Parser (GPX, KML, TCX)
2773
+ */
2774
+ _parseFromXMLString: function _parseFromXMLString(data) {
2775
+ var _Array$from$find;
2776
+
2777
+ if (data.indexOf("<") != 0) {
2778
+ throw 'Invalid XML';
2779
+ }
2780
+
2781
+ var xml = new DOMParser().parseFromString(data, "text/xml");
2782
+ var type = xml.documentElement.tagName.toLowerCase(); // "kml" or "gpx"
2783
+
2784
+ var name = xml.getElementsByTagName('name');
2785
+
2786
+ if (xml.getElementsByTagName('parsererror').length) {
2787
+ throw 'Invalid XML';
2788
+ }
2789
+
2790
+ if (!(type in toGeoJSON)) {
2791
+ type = xml.documentElement.tagName == "TrainingCenterDatabase" ? 'tcx' : 'gpx';
2792
+ }
2793
+
2794
+ var geojson = toGeoJSON[type](xml);
2795
+ geojson.name = name.length > 0 ? ((_Array$from$find = Array.from(name).find(function (tag) {
2796
+ return tag.parentElement.tagName == "trk";
2797
+ })) !== null && _Array$from$find !== void 0 ? _Array$from$find : name[0]).textContent : '';
2798
+ return geojson;
2799
+ },
2800
+
2801
+ /**
2802
+ * Extend GeoJSON properties (name, time, ...)
2803
+ */
2804
+ _prepareAdditionalProperties: function _prepareAdditionalProperties(geojson) {
2805
+ if (!geojson.name && this._downloadURL) {
2806
+ geojson.name = this._downloadURL.split('/').pop().split('#')[0].split('?')[0];
2807
+ }
2808
+
2809
+ return geojson;
2810
+ },
2811
+
2812
+ /**
2813
+ * Just a temporary fix for MultiLineString data (trk > trkseg + trkseg),
2814
+ * just split them into seperate LineStrings (trk > trkseg, trk > trkseg)
2815
+ *
2816
+ * @link https://github.com/Raruto/leaflet-elevation/issues/56
2817
+ */
2818
+ _prepareMultiLineStrings: function _prepareMultiLineStrings(geojson) {
2819
+ geojson.features.forEach(function (feauture) {
2820
+ if (feauture.geometry.type == "MultiLineString") {
2821
+ feauture.geometry.coordinates.forEach(function (coords) {
2822
+ geojson.features.push({
2823
+ geometry: {
2824
+ type: 'LineString',
2825
+ coordinates: coords
2826
+ },
2827
+ properties: feauture.properties,
2828
+ type: 'Feature'
2829
+ });
2830
+ });
2831
+ }
2832
+ });
2833
+ return geojson.features.filter(function (feauture) {
2834
+ return feauture.geometry.type != "MultiLineString";
2835
+ });
2787
2836
  },
2788
2837
 
2789
2838
  /**
2790
- * Add a waypoint marker to the diagram
2839
+ * Add a point of interest over the diagram
2791
2840
  */
2792
2841
  _registerCheckPoint: function _registerCheckPoint(props) {
2793
- var _this10 = this;
2842
+ var _this13 = this;
2794
2843
 
2795
2844
  this.on("elechart_updated", function () {
2796
- return _this10._chart._registerCheckPoint(props);
2845
+ return _this13._chart._registerCheckPoint(props);
2797
2846
  });
2798
2847
  },
2799
2848
 
@@ -2801,10 +2850,10 @@
2801
2850
  * Add chart profile to diagram
2802
2851
  */
2803
2852
  _registerAreaPath: function _registerAreaPath(props) {
2804
- var _this11 = this;
2853
+ var _this14 = this;
2805
2854
 
2806
2855
  this.on("elechart_init", function () {
2807
- return _this11._chart._registerAreaPath(props);
2856
+ return _this14._chart._registerAreaPath(props);
2808
2857
  });
2809
2858
  },
2810
2859
 
@@ -2812,10 +2861,10 @@
2812
2861
  * Add chart grid to diagram
2813
2862
  */
2814
2863
  _registerAxisGrid: function _registerAxisGrid(props) {
2815
- var _this12 = this;
2864
+ var _this15 = this;
2816
2865
 
2817
2866
  this.on("elechart_axis", function () {
2818
- return _this12._chart._registerAxisGrid(props);
2867
+ return _this15._chart._registerAxisGrid(props);
2819
2868
  });
2820
2869
  },
2821
2870
 
@@ -2823,10 +2872,10 @@
2823
2872
  * Add chart axis to diagram
2824
2873
  */
2825
2874
  _registerAxisScale: function _registerAxisScale(props) {
2826
- var _this13 = this;
2875
+ var _this16 = this;
2827
2876
 
2828
2877
  this.on("elechart_axis", function () {
2829
- return _this13._chart._registerAxisScale(props);
2878
+ return _this16._chart._registerAxisScale(props);
2830
2879
  });
2831
2880
  },
2832
2881
 
@@ -2834,14 +2883,14 @@
2834
2883
  * Add chart or marker tooltip info
2835
2884
  */
2836
2885
  _registerTooltip: function _registerTooltip(props) {
2837
- var _this14 = this;
2886
+ var _this17 = this;
2838
2887
 
2839
2888
  if (props.chart) {
2840
2889
  var label = L.extend({}, props, {
2841
2890
  value: props.chart
2842
2891
  });
2843
2892
  this.on("elechart_init", function () {
2844
- return _this14._chart._registerTooltip(label);
2893
+ return _this17._chart._registerTooltip(label);
2845
2894
  });
2846
2895
  }
2847
2896
 
@@ -2851,7 +2900,7 @@
2851
2900
  });
2852
2901
 
2853
2902
  this.on("elechart_marker", function () {
2854
- return _this14._marker._registerTooltip(_label);
2903
+ return _this17._marker._registerTooltip(_label);
2855
2904
  });
2856
2905
  }
2857
2906
  },
@@ -2860,10 +2909,10 @@
2860
2909
  * Add summary info to diagram
2861
2910
  */
2862
2911
  _registerSummary: function _registerSummary(props) {
2863
- var _this15 = this;
2912
+ var _this18 = this;
2864
2913
 
2865
2914
  this.on('elechart_summary', function () {
2866
- return _this15._summary._registerSummary(props);
2915
+ return _this18._summary._registerSummary(props);
2867
2916
  });
2868
2917
  },
2869
2918
 
@@ -2968,7 +3017,7 @@
2968
3017
  * Toggle chart data on legend click
2969
3018
  */
2970
3019
  _toggleChartHandler: function _toggleChartHandler(e) {
2971
- var _this16 = this;
3020
+ var _this19 = this;
2972
3021
 
2973
3022
  var path = e.path,
2974
3023
  name = e.name,
@@ -2978,7 +3027,7 @@
2978
3027
  this._layers.eachLayer(function (layer) {
2979
3028
  var node = layer.getElement && layer.getElement();
2980
3029
 
2981
- toggleClass(node, _this16.options.polyline.className + ' ' + _this16.options.theme, _this16._chartEnabled);
3030
+ toggleClass(node, _this19.options.polyline.className + ' ' + _this19.options.theme, _this19._chartEnabled);
2982
3031
  }); // toggle option value (eg. altitude = { 'disabled' || 'disabled' })
2983
3032
 
2984
3033
 
@@ -3052,7 +3101,7 @@
3052
3101
  * Update chart summary.
3053
3102
  */
3054
3103
  _updateSummary: function _updateSummary() {
3055
- var _this17 = this;
3104
+ var _this20 = this;
3056
3105
 
3057
3106
  this._summary.reset();
3058
3107
 
@@ -3062,14 +3111,22 @@
3062
3111
 
3063
3112
  if (this.options.downloadLink && this._downloadURL) {
3064
3113
  // TODO: generate dynamically file content instead of using static file urls.
3065
- this.summaryDiv.innerHTML += '<span class="download"><a href="#">' + L._('Download') + '</a></span>';
3114
+ this._summary._container.innerHTML += '<span class="download"><a href="#">' + L._('Download') + '</a></span>';
3066
3115
 
3067
- select('.download a', this.summaryDiv).onclick = function (e) {
3116
+ select('.download a', this._summary._container).onclick = function (e) {
3068
3117
  e.preventDefault();
3069
3118
 
3070
- _this17._fireEvt('eletrack_download', {
3071
- downloadLink: _this17.options.downloadLink,
3072
- confirm: saveFile.bind(_this17, _this17._downloadURL)
3119
+ if (e.downloadLink == 'modal' && typeof CustomEvent === "function") {
3120
+ document.dispatchEvent(new CustomEvent("eletrack_download", {
3121
+ detail: e
3122
+ }));
3123
+ } else if (e.downloadLink == 'link' || e.downloadLink === true) {
3124
+ e.confirm();
3125
+ }
3126
+
3127
+ _this20._fireEvt('eletrack_download', {
3128
+ downloadLink: _this20.options.downloadLink,
3129
+ confirm: saveFile.bind(_this20, _this20._downloadURL)
3073
3130
  });
3074
3131
  };
3075
3132
  }
@@ -3100,130 +3157,6 @@
3100
3157
  return this.__yTicks || Math.round(this._height() / 30);
3101
3158
  }
3102
3159
  });
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
3160
 
3228
3161
  Elevation.addInitHook(function () {
3229
3162
  var opts = this.options;
@@ -3904,7 +3837,21 @@
3904
3837
 
3905
3838
  return proto.call(null, string, data);
3906
3839
  };
3907
- })();
3840
+ })(); // Alias deprecated functions
3841
+
3842
+
3843
+ Elevation.addInitHook(function () {
3844
+ this.enableDragging = this.enableBrush;
3845
+ this.disableDragging = this.disableBrush;
3846
+ this.loadChart = this.addTo;
3847
+ this.loadData = this.load;
3848
+ this.loadGPX = this.load;
3849
+ this.loadGeoJSON = this.load;
3850
+ this.loadXML = this.load;
3851
+ this.loadFile = this.load;
3852
+ this._addGPXData = this._addGeoJSONData;
3853
+ this._registerFocusLabel = this._registerTooltip;
3854
+ });
3908
3855
 
3909
3856
  L.control.elevation = function (options) {
3910
3857
  return new Elevation(options);