@raruto/leaflet-elevation 1.7.4 → 1.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +19 -2
- package/dist/leaflet-elevation.js +637 -847
- package/dist/leaflet-elevation.js.map +1 -1
- package/dist/leaflet-elevation.min.js +3 -1
- package/dist/leaflet-elevation.min.js.map +1 -1
- package/package.json +1 -1
- package/src/acceleration.js +11 -21
- package/src/altitude.js +21 -22
- package/src/chart.js +55 -175
- package/src/components.js +159 -111
- package/src/control.js +115 -209
- package/src/distance.js +15 -13
- package/src/index.js +12 -1
- package/src/marker.js +38 -98
- package/src/options.js +1 -8
- package/src/slope.js +9 -18
- package/src/speed.js +11 -21
- package/src/time.js +15 -10
- package/src/utils.js +113 -137
package/src/control.js
CHANGED
|
@@ -17,24 +17,21 @@ export const Elevation = L.Control.Elevation = L.Control.extend({
|
|
|
17
17
|
__TOGEOJSON: 'https://unpkg.com/@tmcw/togeojson@4.3.0/dist/togeojson.umd.js',
|
|
18
18
|
__LGEOMUTIL: 'https://unpkg.com/leaflet-geometryutil@0.9.3/src/leaflet.geometryutil.js',
|
|
19
19
|
__LALMOSTOVER: 'https://unpkg.com/leaflet-almostover@1.0.1/src/leaflet.almostover.js',
|
|
20
|
-
__LDISTANCEM: 'https://unpkg.com/@raruto/leaflet-elevation@1.7.
|
|
20
|
+
__LDISTANCEM: 'https://unpkg.com/@raruto/leaflet-elevation@1.7.5/libs/leaflet-distance-marker.min.js',
|
|
21
21
|
|
|
22
22
|
/*
|
|
23
23
|
* Add data to the diagram either from GPX or GeoJSON and update the axis domain and data
|
|
24
24
|
*/
|
|
25
25
|
addData: function(d, layer) {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
this._addLayer(layer);
|
|
36
|
-
this._fireEvt("eledata_added", { data: d, layer: layer, track_info: this.track_info });
|
|
37
|
-
});
|
|
26
|
+
this.lazyLoad(this.__D3)
|
|
27
|
+
.then(() => {
|
|
28
|
+
if (typeof layer === "undefined" && d.on) {
|
|
29
|
+
layer = d;
|
|
30
|
+
}
|
|
31
|
+
this._addData(d);
|
|
32
|
+
this._addLayer(layer);
|
|
33
|
+
this._fireEvt("eledata_added", { data: d, layer: layer, track_info: this.track_info });
|
|
34
|
+
});
|
|
38
35
|
},
|
|
39
36
|
|
|
40
37
|
/**
|
|
@@ -107,20 +104,6 @@ export const Elevation = L.Control.Elevation = L.Control.extend({
|
|
|
107
104
|
this._chart._brushEnabled = true;
|
|
108
105
|
},
|
|
109
106
|
|
|
110
|
-
/**
|
|
111
|
-
* Alias for enableBrush
|
|
112
|
-
*/
|
|
113
|
-
enableDragging: function() {
|
|
114
|
-
this.enableBrushing();
|
|
115
|
-
},
|
|
116
|
-
|
|
117
|
-
/**
|
|
118
|
-
* Alias for disableBrush
|
|
119
|
-
*/
|
|
120
|
-
disableDragging: function() {
|
|
121
|
-
this.disableBrushing();
|
|
122
|
-
},
|
|
123
|
-
|
|
124
107
|
/**
|
|
125
108
|
* Disable chart zooming.
|
|
126
109
|
*/
|
|
@@ -153,7 +136,7 @@ export const Elevation = L.Control.Elevation = L.Control.extend({
|
|
|
153
136
|
* Get default zoom level when "followMarker" is true.
|
|
154
137
|
*/
|
|
155
138
|
getZFollow: function() {
|
|
156
|
-
return this.
|
|
139
|
+
return this.options.zFollow;
|
|
157
140
|
},
|
|
158
141
|
|
|
159
142
|
/**
|
|
@@ -172,60 +155,32 @@ export const Elevation = L.Control.Elevation = L.Control.extend({
|
|
|
172
155
|
this._markers = L.featureGroup();
|
|
173
156
|
this._markedSegments = L.polyline([]);
|
|
174
157
|
this._chartEnabled = true,
|
|
175
|
-
|
|
176
158
|
this.track_info = {};
|
|
177
|
-
|
|
178
159
|
this.options = _.deepMerge({}, this.options, options);
|
|
179
160
|
|
|
180
|
-
this.
|
|
181
|
-
|
|
182
|
-
if (this.options.
|
|
183
|
-
if (this.options.
|
|
184
|
-
|
|
185
|
-
if (this.options.legend) this.options.margins.bottom += 30;
|
|
186
|
-
|
|
187
|
-
if (this.options.theme) this.options.polylineSegments.className += ' ' + this.options.theme;
|
|
161
|
+
if (this.options.followMarker) this._setMapView = L.Util.throttle(this._setMapView, 300, this);
|
|
162
|
+
if (this.options.legend) this.options.margins.bottom += 30;
|
|
163
|
+
if (this.options.theme) this.options.polylineSegments.className += ' ' + this.options.theme;
|
|
164
|
+
if (this.options.wptIcons === true) this.options.wptIcons = Options.wptIcons;
|
|
188
165
|
|
|
189
166
|
this._markedSegments.setStyle(this.options.polylineSegments);
|
|
190
167
|
|
|
191
|
-
// this._resizeChart = _.debounce(this._resizeChart, 300, this);
|
|
192
|
-
// this._resizeChart = L.Util.throttle(this._resizeChart, 300, this);
|
|
193
|
-
|
|
194
|
-
// if (L.Browser.mobile) {
|
|
195
|
-
// this._updateChart = _.debounce(this._updateChart, 300, this);
|
|
196
|
-
// this._updateSummary = _.debounce(this._updateSummary, 300, this);
|
|
197
|
-
// }
|
|
198
|
-
|
|
199
|
-
if (this.options.wptIcons === true) this.options.wptIcons = Options.wptIcons;
|
|
200
|
-
|
|
201
168
|
// Leaflet canvas renderer colors
|
|
202
169
|
L.extend(D3.Colors, this.options.colors || {});
|
|
203
170
|
},
|
|
204
171
|
|
|
205
172
|
/**
|
|
206
|
-
*
|
|
173
|
+
* Javascript scripts downloader (lazy loader)
|
|
207
174
|
*/
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
},
|
|
211
|
-
|
|
212
|
-
/**
|
|
213
|
-
* Alias for addTo
|
|
214
|
-
*/
|
|
215
|
-
loadChart: function(map) {
|
|
216
|
-
this.addTo(map);
|
|
175
|
+
lazyLoad: function(src) {
|
|
176
|
+
return _.lazyLoad(src, this);
|
|
217
177
|
},
|
|
218
178
|
|
|
219
179
|
/**
|
|
220
180
|
* Load elevation data (GPX, GeoJSON or KML).
|
|
221
181
|
*/
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
if (opts.defer) {
|
|
225
|
-
this.loadDefer(data, opts);
|
|
226
|
-
} else if (opts.lazy) {
|
|
227
|
-
this.loadLazy(data, opts);
|
|
228
|
-
} else if (_.isXMLDoc(data)) {
|
|
182
|
+
load: function(data) {
|
|
183
|
+
if (_.isXMLDoc(data)) {
|
|
229
184
|
this.loadXML(data);
|
|
230
185
|
} else if (_.isJSONDoc(data)) {
|
|
231
186
|
this.loadGeoJSON(data);
|
|
@@ -234,15 +189,6 @@ export const Elevation = L.Control.Elevation = L.Control.extend({
|
|
|
234
189
|
}
|
|
235
190
|
},
|
|
236
191
|
|
|
237
|
-
/**
|
|
238
|
-
* Wait for document load before download data.
|
|
239
|
-
*/
|
|
240
|
-
loadDefer: function(data, opts) {
|
|
241
|
-
opts = L.extend({}, this.options.loadData, opts);
|
|
242
|
-
opts.defer = false;
|
|
243
|
-
_.deferFunc(L.bind(this.loadData, this, data, opts));
|
|
244
|
-
},
|
|
245
|
-
|
|
246
192
|
/**
|
|
247
193
|
* Load data from a remote url.
|
|
248
194
|
*/
|
|
@@ -251,7 +197,7 @@ export const Elevation = L.Control.Elevation = L.Control.extend({
|
|
|
251
197
|
.then((response) => response.text())
|
|
252
198
|
.then((data) => {
|
|
253
199
|
this._downloadURL = url; // TODO: handle multiple urls?
|
|
254
|
-
this.
|
|
200
|
+
this.load(data);
|
|
255
201
|
})
|
|
256
202
|
.catch((err) => console.warn(err));
|
|
257
203
|
},
|
|
@@ -263,23 +209,12 @@ export const Elevation = L.Control.Elevation = L.Control.extend({
|
|
|
263
209
|
_.GeoJSONLoader(data, this);
|
|
264
210
|
},
|
|
265
211
|
|
|
266
|
-
/**
|
|
267
|
-
* Alias for loadXML
|
|
268
|
-
*/
|
|
269
|
-
loadGPX: function(data){
|
|
270
|
-
this.loadXML(data);
|
|
271
|
-
},
|
|
272
|
-
|
|
273
212
|
/**
|
|
274
213
|
* Load raw XML data.
|
|
275
214
|
*/
|
|
276
215
|
loadXML: function(data) {
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
typeof toGeoJSON !== 'function' || !this.options.lazyLoadJS,
|
|
280
|
-
Elevation._togeojsonLazyLoader
|
|
281
|
-
).then(
|
|
282
|
-
() => {
|
|
216
|
+
this.lazyLoad(this.__TOGEOJSON)
|
|
217
|
+
.then(() => {
|
|
283
218
|
let xml = (new DOMParser()).parseFromString(data, "text/xml");
|
|
284
219
|
let type = xml.documentElement.tagName.toLowerCase(); // "kml" or "gpx"
|
|
285
220
|
if (!(type in toGeoJSON)) {
|
|
@@ -291,21 +226,6 @@ export const Elevation = L.Control.Elevation = L.Control.extend({
|
|
|
291
226
|
else if(this._downloadURL) { geojson.name = this._downloadURL.split('/').pop().split('#')[0].split('?')[0]; }
|
|
292
227
|
|
|
293
228
|
return this.loadGeoJSON(geojson, this);
|
|
294
|
-
}
|
|
295
|
-
);
|
|
296
|
-
},
|
|
297
|
-
|
|
298
|
-
/**
|
|
299
|
-
* Wait for chart container visible before download data.
|
|
300
|
-
*/
|
|
301
|
-
loadLazy: function(data, opts) {
|
|
302
|
-
opts = L.extend({}, this.options.loadData, opts);
|
|
303
|
-
let elem = opts.lazy.parentNode ? opts.lazy : this.placeholder;
|
|
304
|
-
_.waitHolder(elem)
|
|
305
|
-
.then(() => {
|
|
306
|
-
opts.lazy = false;
|
|
307
|
-
this.loadData(data, opts)
|
|
308
|
-
this.once('eledata_loaded', () => this.placeholder.parentNode.removeChild(elem));
|
|
309
229
|
});
|
|
310
230
|
},
|
|
311
231
|
|
|
@@ -321,40 +241,31 @@ export const Elevation = L.Control.Elevation = L.Control.extend({
|
|
|
321
241
|
if (!this.options.detached) {
|
|
322
242
|
_.addClass(container, 'leaflet-control');
|
|
323
243
|
}
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
.
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
_.on(map.getContainer(), 'touchstart', this._resetDrag, this);
|
|
350
|
-
|
|
351
|
-
this
|
|
352
|
-
.on('eledata_added eledata_loaded', this._updateChart, this)
|
|
353
|
-
.on('eledata_added eledata_loaded', this._updateSummary, this);
|
|
354
|
-
|
|
355
|
-
this._updateChart();
|
|
356
|
-
this._updateSummary();
|
|
357
|
-
});
|
|
244
|
+
this.lazyLoad(this.__D3)
|
|
245
|
+
.then(() => {
|
|
246
|
+
this._initButton(container);
|
|
247
|
+
this._initChart(container);
|
|
248
|
+
this._initSummary(container);
|
|
249
|
+
this._initMarker(map);
|
|
250
|
+
this._initLayer(map);
|
|
251
|
+
|
|
252
|
+
map
|
|
253
|
+
.on('zoom viewreset zoomanim', this._hideMarker, this)
|
|
254
|
+
.on('resize', this._resetView, this)
|
|
255
|
+
.on('resize', this._resizeChart, this)
|
|
256
|
+
.on('rotate', this._rotateMarker, this)
|
|
257
|
+
.on('mousedown', this._resetDrag, this);
|
|
258
|
+
|
|
259
|
+
_.on(map.getContainer(), 'mousewheel', this._resetDrag, this);
|
|
260
|
+
_.on(map.getContainer(), 'touchstart', this._resetDrag, this);
|
|
261
|
+
|
|
262
|
+
this
|
|
263
|
+
.on('eledata_added eledata_loaded', this._updateChart, this)
|
|
264
|
+
.on('eledata_added eledata_loaded', this._updateSummary, this);
|
|
265
|
+
|
|
266
|
+
this._updateChart();
|
|
267
|
+
this._updateSummary();
|
|
268
|
+
});
|
|
358
269
|
|
|
359
270
|
return container;
|
|
360
271
|
},
|
|
@@ -391,7 +302,7 @@ export const Elevation = L.Control.Elevation = L.Control.extend({
|
|
|
391
302
|
* Set default zoom level when "followMarker" is true.
|
|
392
303
|
*/
|
|
393
304
|
setZFollow: function(zoom) {
|
|
394
|
-
this.
|
|
305
|
+
this.options.zFollow = zoom;
|
|
395
306
|
},
|
|
396
307
|
|
|
397
308
|
/**
|
|
@@ -450,7 +361,7 @@ export const Elevation = L.Control.Elevation = L.Control.extend({
|
|
|
450
361
|
*/
|
|
451
362
|
_addGPXData: function(coords) {
|
|
452
363
|
_.each(coords, point => {
|
|
453
|
-
this._addPoint(point.lat, point.lng,
|
|
364
|
+
this._addPoint(point.lat, point.lng, point.alt ?? point.meta.ele);
|
|
454
365
|
this._fireEvt("elepoint_added", { point: point, index: this._data.length - 1 });
|
|
455
366
|
});
|
|
456
367
|
this._fireEvt("eletrack_added", { coords: coords, index: this._data.length - 1 });
|
|
@@ -561,17 +472,15 @@ export const Elevation = L.Control.Elevation = L.Control.extend({
|
|
|
561
472
|
opts.xTicks = this._xTicks();
|
|
562
473
|
opts.yTicks = this._yTicks();
|
|
563
474
|
|
|
564
|
-
if (opts.
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
}
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
if (opts._maxWidth > clientWidth) opts.width = clientWidth - 30;
|
|
574
|
-
}
|
|
475
|
+
if (opts.detached) {
|
|
476
|
+
let { offsetWidth, offsetHeight} = this.eleDiv;
|
|
477
|
+
if (offsetWidth > 0) opts.width = offsetWidth;
|
|
478
|
+
if (offsetHeight > 20) opts.height = offsetHeight - 20; // 20 = horizontal scrollbar size.
|
|
479
|
+
} else {
|
|
480
|
+
let { clientWidth } = this._map.getContainer();
|
|
481
|
+
opts._maxWidth = opts._maxWidth > opts.width ? opts._maxWidth : opts.width;
|
|
482
|
+
this._container.style.maxWidth = opts._maxWidth + 'px';
|
|
483
|
+
if (opts._maxWidth > clientWidth) opts.width = clientWidth - 30;
|
|
575
484
|
}
|
|
576
485
|
|
|
577
486
|
let chart = this._chart = new Chart(opts, this);
|
|
@@ -636,8 +545,8 @@ export const Elevation = L.Control.Elevation = L.Control.extend({
|
|
|
636
545
|
|
|
637
546
|
if (!this.options.detached) {
|
|
638
547
|
L.DomEvent
|
|
639
|
-
.disableClickPropagation(container)
|
|
640
|
-
|
|
548
|
+
.disableClickPropagation(container)
|
|
549
|
+
.disableScrollPropagation(container);
|
|
641
550
|
}
|
|
642
551
|
|
|
643
552
|
if (L.Browser.mobile) {
|
|
@@ -790,14 +699,14 @@ export const Elevation = L.Control.Elevation = L.Control.extend({
|
|
|
790
699
|
/**
|
|
791
700
|
* Add chart or marker tooltip info
|
|
792
701
|
*/
|
|
793
|
-
|
|
702
|
+
_registerTooltip: function(props) {
|
|
794
703
|
if (props.chart) {
|
|
795
704
|
let label = L.extend({}, props, { value: props.chart });
|
|
796
|
-
this.on("elechart_init", () => this._chart.
|
|
705
|
+
this.on("elechart_init", () => this._chart._registerTooltip(label));
|
|
797
706
|
}
|
|
798
707
|
if (props.marker) {
|
|
799
708
|
let label = L.extend({}, props, { value: props.marker });
|
|
800
|
-
this.on("elechart_marker", () => this._marker.
|
|
709
|
+
this.on("elechart_marker", () => this._marker._registerTooltip(label));
|
|
801
710
|
}
|
|
802
711
|
},
|
|
803
712
|
|
|
@@ -832,28 +741,30 @@ export const Elevation = L.Control.Elevation = L.Control.extend({
|
|
|
832
741
|
* Hacky way for handling chart resize. Deletes it and redraw chart.
|
|
833
742
|
*/
|
|
834
743
|
_resizeChart: function() {
|
|
744
|
+
if(!this._container) return;
|
|
745
|
+
|
|
835
746
|
// prevent displaying chart on resize if hidden
|
|
836
747
|
if (_.style(this._container, "display") == "none") return;
|
|
837
748
|
|
|
838
749
|
let opts = this.options;
|
|
839
750
|
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
751
|
+
let newWidth;
|
|
752
|
+
|
|
753
|
+
if (opts.detached) {
|
|
754
|
+
newWidth = (this.eleDiv || this._container).offsetWidth;
|
|
755
|
+
} else {
|
|
756
|
+
let { clientWidth } = this._map.getContainer();
|
|
757
|
+
newWidth = opts._maxWidth > clientWidth ? clientWidth - 30 : opts._maxWidth;
|
|
758
|
+
}
|
|
759
|
+
|
|
760
|
+
if (newWidth) {
|
|
761
|
+
let chart = this._chart;
|
|
762
|
+
opts.width = newWidth;
|
|
763
|
+
if (chart && chart._chart) {
|
|
764
|
+
chart._chart._resize(opts);
|
|
765
|
+
opts.xTicks = this._xTicks();
|
|
766
|
+
opts.yTicks = this._yTicks();
|
|
767
|
+
this._updateChart();
|
|
857
768
|
}
|
|
858
769
|
}
|
|
859
770
|
|
|
@@ -883,9 +794,9 @@ export const Elevation = L.Control.Elevation = L.Control.extend({
|
|
|
883
794
|
_setMapView: function(item) {
|
|
884
795
|
if (!this.options.followMarker || !this._map) return;
|
|
885
796
|
let zoom = this._map.getZoom();
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
this._map.setView(item.latlng, zoom, { animate: true, duration: 0.25 });
|
|
797
|
+
let z = this.options.zFollow;
|
|
798
|
+
if (typeof z === "number") {
|
|
799
|
+
this._map.setView(item.latlng, (zoom < z ? z : zoom), { animate: true, duration: 0.25 });
|
|
889
800
|
} else if (!this._map.getBounds().contains(item.latlng)) {
|
|
890
801
|
this._map.setView(item.latlng, zoom, { animate: true, duration: 0.25 });
|
|
891
802
|
}
|
|
@@ -920,7 +831,7 @@ export const Elevation = L.Control.Elevation = L.Control.extend({
|
|
|
920
831
|
* Calculates [x, y] domain and then update chart.
|
|
921
832
|
*/
|
|
922
833
|
_updateChart: function() {
|
|
923
|
-
if (/*!this._data.length ||*/ !this._container) return;
|
|
834
|
+
if (/*!this._data.length ||*/ !this._chart || !this._container) return;
|
|
924
835
|
|
|
925
836
|
this._fireEvt("elechart_axis");
|
|
926
837
|
this._fireEvt("elechart_area");
|
|
@@ -937,21 +848,23 @@ export const Elevation = L.Control.Elevation = L.Control.extend({
|
|
|
937
848
|
* Update the position/height indicator marker drawn onto the map
|
|
938
849
|
*/
|
|
939
850
|
_updateMarker: function(item) {
|
|
940
|
-
if (
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
851
|
+
if (this._marker) {
|
|
852
|
+
this._marker.update({
|
|
853
|
+
map : this._map,
|
|
854
|
+
item : item,
|
|
855
|
+
maxElevation: this.track_info.elevation_max || 0,
|
|
856
|
+
options : this.options
|
|
857
|
+
});
|
|
858
|
+
}
|
|
947
859
|
},
|
|
948
860
|
|
|
949
861
|
/**
|
|
950
862
|
* Fix marker rotation on rotated maps
|
|
951
863
|
*/
|
|
952
864
|
_rotateMarker: function() {
|
|
953
|
-
if (
|
|
954
|
-
|
|
865
|
+
if (this._marker) {
|
|
866
|
+
this._marker.update();
|
|
867
|
+
}
|
|
955
868
|
},
|
|
956
869
|
|
|
957
870
|
/**
|
|
@@ -1015,6 +928,13 @@ export const Elevation = L.Control.Elevation = L.Control.extend({
|
|
|
1015
928
|
*/
|
|
1016
929
|
Elevation.addInitHook(function() {
|
|
1017
930
|
|
|
931
|
+
// Alias deprecated functions
|
|
932
|
+
this.enableDragging = this.enableBrush;
|
|
933
|
+
this.disableDragging = this.disableBrush;
|
|
934
|
+
this.loadChart = this.addTo;
|
|
935
|
+
this.loadData = this.load;
|
|
936
|
+
this.loadGPX = this.loadXML;
|
|
937
|
+
|
|
1018
938
|
this.on('waypoint_added', function(e) {
|
|
1019
939
|
let p = e.point,
|
|
1020
940
|
pop = p._popup;
|
|
@@ -1051,45 +971,31 @@ Elevation.addInitHook(function() {
|
|
|
1051
971
|
} else {
|
|
1052
972
|
|
|
1053
973
|
// leaflet-geometryutil
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
typeof L.GeometryUtil !== 'function' || !this.options.lazyLoadJS,
|
|
1057
|
-
Elevation._geomutilLazyLoader
|
|
1058
|
-
).then(
|
|
1059
|
-
() => {
|
|
974
|
+
this.lazyLoad(this.__LGEOMUTIL)
|
|
975
|
+
.then(() => {
|
|
1060
976
|
|
|
1061
977
|
// leaflet-almostover
|
|
1062
978
|
if (this.options.almostOver) {
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
Elevation._almostoverLazyLoader
|
|
1067
|
-
).then(
|
|
1068
|
-
() => {
|
|
1069
|
-
map.addHandler('almostOver',L.Handler.AlmostOver)
|
|
979
|
+
this.lazyLoad(this.__LALMOSTOVER)
|
|
980
|
+
.then(() => {
|
|
981
|
+
map.addHandler('almostOver', L.Handler.AlmostOver)
|
|
1070
982
|
if (L.GeometryUtil && map.almostOver && map.almostOver.enabled()) {
|
|
1071
983
|
map.almostOver.addLayer(layer);
|
|
1072
984
|
map
|
|
1073
985
|
.on('almost:move', (e) => this._mousemoveLayerHandler(e))
|
|
1074
986
|
.on('almost:out', (e) => this._mouseoutHandler(e));
|
|
1075
987
|
}
|
|
1076
|
-
}
|
|
1077
|
-
);
|
|
988
|
+
});
|
|
1078
989
|
}
|
|
1079
990
|
|
|
1080
991
|
// leaflet-distance-markers
|
|
1081
992
|
if (this.options.distanceMarkers) {
|
|
1082
|
-
|
|
1083
|
-
this.
|
|
1084
|
-
typeof L.DistanceMarkers !== 'function' || !this.options.lazyLoadJS,
|
|
1085
|
-
Elevation._distanceMarkersLazyLoader
|
|
1086
|
-
).then(() => this.options.polyline && layer.addTo(map));
|
|
993
|
+
this.lazyLoad(this.__LDISTANCEM)
|
|
994
|
+
.then(() => this.options.polyline && layer.addTo(map));
|
|
1087
995
|
} else {
|
|
1088
996
|
if (this.options.polyline) layer.addTo(map);
|
|
1089
997
|
}
|
|
1090
|
-
}
|
|
1091
|
-
|
|
1092
|
-
);
|
|
998
|
+
});
|
|
1093
999
|
}
|
|
1094
1000
|
});
|
|
1095
1001
|
|
|
@@ -1112,7 +1018,7 @@ Elevation.addInitHook(function() {
|
|
|
1112
1018
|
if (options.stroke && options.weight !== 0) {
|
|
1113
1019
|
let oldVal = ctx.globalCompositeOperation || 'source-over';
|
|
1114
1020
|
ctx.globalCompositeOperation = 'destination-over'
|
|
1115
|
-
ctx.strokeStyle = '#FFF';
|
|
1021
|
+
ctx.strokeStyle = color.outline || '#FFF';
|
|
1116
1022
|
ctx.lineWidth = options.weight * 1.75;
|
|
1117
1023
|
ctx.stroke();
|
|
1118
1024
|
ctx.globalCompositeOperation = oldVal;
|
package/src/distance.js
CHANGED
|
@@ -8,12 +8,12 @@ Elevation.addInitHook(function() {
|
|
|
8
8
|
let opts = this.options;
|
|
9
9
|
let distance = {};
|
|
10
10
|
|
|
11
|
-
if (
|
|
12
|
-
|
|
13
|
-
|
|
11
|
+
if (opts.imperial) {
|
|
12
|
+
opts.distanceFactor = this.__mileFactor;
|
|
13
|
+
distance.label = "mi";
|
|
14
14
|
} else {
|
|
15
|
-
|
|
16
|
-
|
|
15
|
+
opts.distanceFactor = opts.distanceFactor || 1;
|
|
16
|
+
distance.label = opts.xLabel;
|
|
17
17
|
}
|
|
18
18
|
|
|
19
19
|
this.on("eledata_updated", function(e) {
|
|
@@ -26,13 +26,13 @@ Elevation.addInitHook(function() {
|
|
|
26
26
|
let curr = data[i].latlng;
|
|
27
27
|
let prev = i > 0 ? data[i - 1].latlng : curr;
|
|
28
28
|
|
|
29
|
-
let delta = curr.distanceTo(prev) *
|
|
29
|
+
let delta = curr.distanceTo(prev) * opts.distanceFactor;
|
|
30
30
|
|
|
31
31
|
dist += Math.round(delta / 1000 * 100000) / 100000; // handles floating points calc
|
|
32
32
|
|
|
33
|
-
data[i].dist = dist;
|
|
34
|
-
|
|
35
33
|
track.distance = dist;
|
|
34
|
+
|
|
35
|
+
data[i].dist = dist;
|
|
36
36
|
});
|
|
37
37
|
|
|
38
38
|
this.on("elechart_axis", function() {
|
|
@@ -49,13 +49,10 @@ Elevation.addInitHook(function() {
|
|
|
49
49
|
|
|
50
50
|
this.on("elechart_axis", function() {
|
|
51
51
|
|
|
52
|
-
distance.x = this._chart._x;
|
|
53
|
-
distance.label = this._chart._xLabel;
|
|
54
|
-
|
|
55
52
|
this._chart._registerAxisScale({
|
|
56
53
|
axis : "x",
|
|
57
54
|
position: "bottom",
|
|
58
|
-
scale :
|
|
55
|
+
scale : this._chart._x,
|
|
59
56
|
label : distance.label,
|
|
60
57
|
labelY : 25,
|
|
61
58
|
labelX : () => this._width() + 6,
|
|
@@ -66,10 +63,15 @@ Elevation.addInitHook(function() {
|
|
|
66
63
|
|
|
67
64
|
}
|
|
68
65
|
|
|
66
|
+
this._registerTooltip({
|
|
67
|
+
name: 'x',
|
|
68
|
+
chart: (item) => L._("x: ") + d3.format("." + opts.decimalsX + "f")(item[opts.xAttr]) + " " + distance.label,
|
|
69
|
+
});
|
|
70
|
+
|
|
69
71
|
this._registerSummary({
|
|
70
72
|
"totlen" : {
|
|
71
73
|
label: "Total Length: ",
|
|
72
|
-
value: (track) => (track.distance || 0).toFixed(2) + ' ' +
|
|
74
|
+
value: (track) => (track.distance || 0).toFixed(2) + ' ' + distance.label
|
|
73
75
|
}
|
|
74
76
|
});
|
|
75
77
|
|
package/src/index.js
CHANGED
|
@@ -39,8 +39,8 @@ import * as _ from './utils';
|
|
|
39
39
|
import * as D3 from './components';
|
|
40
40
|
import { Chart } from './chart';
|
|
41
41
|
import { Elevation } from './control';
|
|
42
|
-
import './distance';
|
|
43
42
|
import './altitude';
|
|
43
|
+
import './distance';
|
|
44
44
|
import './time';
|
|
45
45
|
import './slope';
|
|
46
46
|
import './speed';
|
|
@@ -50,4 +50,15 @@ Elevation.Utils = _;
|
|
|
50
50
|
Elevation.Components = D3;
|
|
51
51
|
Elevation.Chart = Chart;
|
|
52
52
|
|
|
53
|
+
/* Temporary fix for empty values evaluated as false (leaflet-i18n v0.3.1) */
|
|
54
|
+
(function(){
|
|
55
|
+
let proto = L.i18n.bind({});
|
|
56
|
+
L.i18n = L._ = (string, data) => {
|
|
57
|
+
if (L.locale && L.locales[L.locale] && L.locales[L.locale][string] == "") {
|
|
58
|
+
L.locales[L.locale][string] = "\u200B";
|
|
59
|
+
}
|
|
60
|
+
return proto.call(null, string, data);
|
|
61
|
+
};
|
|
62
|
+
})();
|
|
63
|
+
|
|
53
64
|
L.control.elevation = (options) => new Elevation(options);
|