@raruto/leaflet-elevation 1.7.6 → 1.8.2
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 +14 -0
- package/dist/leaflet-elevation.css +0 -1
- package/dist/leaflet-elevation.js +604 -790
- package/dist/leaflet-elevation.js.map +1 -1
- package/dist/leaflet-elevation.min.css +1 -1
- package/dist/leaflet-elevation.min.js +2 -2
- package/dist/leaflet-elevation.min.js.map +1 -1
- package/package.json +1 -1
- package/src/acceleration.js +10 -20
- package/src/altitude.js +18 -25
- package/src/chart.js +93 -156
- package/src/components.js +135 -99
- package/src/control.js +112 -207
- package/src/distance.js +12 -15
- package/src/index.css +0 -1
- package/src/marker.js +38 -81
- package/src/options.js +0 -8
- package/src/slope.js +8 -17
- package/src/speed.js +9 -19
- package/src/time.js +7 -7
- package/src/utils.js +77 -99
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.
|
|
20
|
+
__LDISTANCEM: 'https://unpkg.com/@raruto/leaflet-elevation@1.8.2/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
|
|
|
@@ -839,23 +748,23 @@ export const Elevation = L.Control.Elevation = L.Control.extend({
|
|
|
839
748
|
|
|
840
749
|
let opts = this.options;
|
|
841
750
|
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
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();
|
|
859
768
|
}
|
|
860
769
|
}
|
|
861
770
|
|
|
@@ -885,9 +794,9 @@ export const Elevation = L.Control.Elevation = L.Control.extend({
|
|
|
885
794
|
_setMapView: function(item) {
|
|
886
795
|
if (!this.options.followMarker || !this._map) return;
|
|
887
796
|
let zoom = this._map.getZoom();
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
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 });
|
|
891
800
|
} else if (!this._map.getBounds().contains(item.latlng)) {
|
|
892
801
|
this._map.setView(item.latlng, zoom, { animate: true, duration: 0.25 });
|
|
893
802
|
}
|
|
@@ -939,21 +848,23 @@ export const Elevation = L.Control.Elevation = L.Control.extend({
|
|
|
939
848
|
* Update the position/height indicator marker drawn onto the map
|
|
940
849
|
*/
|
|
941
850
|
_updateMarker: function(item) {
|
|
942
|
-
if (
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
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
|
+
}
|
|
949
859
|
},
|
|
950
860
|
|
|
951
861
|
/**
|
|
952
862
|
* Fix marker rotation on rotated maps
|
|
953
863
|
*/
|
|
954
864
|
_rotateMarker: function() {
|
|
955
|
-
if (
|
|
956
|
-
|
|
865
|
+
if (this._marker) {
|
|
866
|
+
this._marker.update();
|
|
867
|
+
}
|
|
957
868
|
},
|
|
958
869
|
|
|
959
870
|
/**
|
|
@@ -1017,6 +928,13 @@ export const Elevation = L.Control.Elevation = L.Control.extend({
|
|
|
1017
928
|
*/
|
|
1018
929
|
Elevation.addInitHook(function() {
|
|
1019
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
|
+
|
|
1020
938
|
this.on('waypoint_added', function(e) {
|
|
1021
939
|
let p = e.point,
|
|
1022
940
|
pop = p._popup;
|
|
@@ -1053,46 +971,33 @@ Elevation.addInitHook(function() {
|
|
|
1053
971
|
} else {
|
|
1054
972
|
|
|
1055
973
|
// leaflet-geometryutil
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
typeof L.GeometryUtil !== 'function' || !this.options.lazyLoadJS,
|
|
1059
|
-
Elevation._geomutilLazyLoader
|
|
1060
|
-
).then(
|
|
1061
|
-
() => {
|
|
974
|
+
this.lazyLoad(this.__LGEOMUTIL)
|
|
975
|
+
.then(() => {
|
|
1062
976
|
|
|
1063
977
|
// leaflet-almostover
|
|
1064
978
|
if (this.options.almostOver) {
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
Elevation._almostoverLazyLoader
|
|
1069
|
-
).then(
|
|
1070
|
-
() => {
|
|
1071
|
-
map.addHandler('almostOver',L.Handler.AlmostOver)
|
|
979
|
+
this.lazyLoad(this.__LALMOSTOVER)
|
|
980
|
+
.then(() => {
|
|
981
|
+
map.addHandler('almostOver', L.Handler.AlmostOver)
|
|
1072
982
|
if (L.GeometryUtil && map.almostOver && map.almostOver.enabled()) {
|
|
1073
983
|
map.almostOver.addLayer(layer);
|
|
1074
984
|
map
|
|
1075
985
|
.on('almost:move', (e) => this._mousemoveLayerHandler(e))
|
|
1076
986
|
.on('almost:out', (e) => this._mouseoutHandler(e));
|
|
1077
987
|
}
|
|
1078
|
-
}
|
|
1079
|
-
);
|
|
988
|
+
});
|
|
1080
989
|
}
|
|
1081
990
|
|
|
1082
991
|
// leaflet-distance-markers
|
|
1083
992
|
if (this.options.distanceMarkers) {
|
|
1084
|
-
|
|
1085
|
-
this.
|
|
1086
|
-
typeof L.DistanceMarkers !== 'function' || !this.options.lazyLoadJS,
|
|
1087
|
-
Elevation._distanceMarkersLazyLoader
|
|
1088
|
-
).then(() => this.options.polyline && layer.addTo(map));
|
|
993
|
+
this.lazyLoad(this.__LDISTANCEM)
|
|
994
|
+
.then(() => this.options.polyline && layer.addTo(map));
|
|
1089
995
|
} else {
|
|
1090
996
|
if (this.options.polyline) layer.addTo(map);
|
|
1091
997
|
}
|
|
1092
|
-
}
|
|
1093
|
-
|
|
1094
|
-
);
|
|
998
|
+
});
|
|
1095
999
|
}
|
|
1000
|
+
|
|
1096
1001
|
});
|
|
1097
1002
|
|
|
1098
1003
|
// Basic canvas renderer support.
|
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,15 +63,15 @@ Elevation.addInitHook(function() {
|
|
|
66
63
|
|
|
67
64
|
}
|
|
68
65
|
|
|
69
|
-
this.
|
|
66
|
+
this._registerTooltip({
|
|
70
67
|
name: 'x',
|
|
71
|
-
chart: (item) => L._("x: ") + d3.format("." + opts.decimalsX + "f")(item[opts.xAttr]) + " " +
|
|
68
|
+
chart: (item) => L._("x: ") + d3.format("." + opts.decimalsX + "f")(item[opts.xAttr]) + " " + distance.label,
|
|
72
69
|
});
|
|
73
70
|
|
|
74
71
|
this._registerSummary({
|
|
75
72
|
"totlen" : {
|
|
76
73
|
label: "Total Length: ",
|
|
77
|
-
value: (track) => (track.distance || 0).toFixed(2) + ' ' +
|
|
74
|
+
value: (track) => (track.distance || 0).toFixed(2) + ' ' + distance.label
|
|
78
75
|
}
|
|
79
76
|
});
|
|
80
77
|
|