@raruto/leaflet-elevation 2.0.7 → 2.0.8
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/src/control.js
CHANGED
|
@@ -55,7 +55,8 @@ export const Elevation = L.Control.Elevation = L.Control.extend({
|
|
|
55
55
|
if (this._chart) this._clearChart();
|
|
56
56
|
if (this._layers) this._clearLayers(this._layers);
|
|
57
57
|
if (this._markers) this._clearLayers(this._markers);
|
|
58
|
-
if (this._circleMarkers) this.
|
|
58
|
+
if (this._circleMarkers) this._circleMarkers.remove();
|
|
59
|
+
if (this._hotline) this._clearLayers(this._hotline);
|
|
59
60
|
|
|
60
61
|
this._data = [];
|
|
61
62
|
this.track_info = {};
|
|
@@ -165,6 +166,7 @@ export const Elevation = L.Control.Elevation = L.Control.extend({
|
|
|
165
166
|
this._data = [];
|
|
166
167
|
this._layers = L.featureGroup();
|
|
167
168
|
this._markers = L.featureGroup();
|
|
169
|
+
this._hotline = L.featureGroup();
|
|
168
170
|
this._circleMarkers = L.featureGroup();
|
|
169
171
|
this._markedSegments = L.polyline([]);
|
|
170
172
|
this._start = (opts.trkStart || Options.trkStart);
|
|
@@ -236,12 +238,15 @@ export const Elevation = L.Control.Elevation = L.Control.extend({
|
|
|
236
238
|
...this.options.handlers
|
|
237
239
|
].filter(m => false !== this.options[typeof m == "string" && m.toLowerCase()]);
|
|
238
240
|
|
|
239
|
-
this._loadModules(modules)
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
241
|
+
this._loadModules(modules).then(() => { // Inject here required modules (data handlers)
|
|
242
|
+
this._initChart(container);
|
|
243
|
+
this._initButton(container);
|
|
244
|
+
this._initSummary(container);
|
|
245
|
+
this._initMarker(map);
|
|
246
|
+
this._initLayer(map);
|
|
247
|
+
});
|
|
248
|
+
|
|
249
|
+
this.fire('add');
|
|
245
250
|
|
|
246
251
|
return container;
|
|
247
252
|
},
|
|
@@ -266,6 +271,8 @@ export const Elevation = L.Control.Elevation = L.Control.extend({
|
|
|
266
271
|
this
|
|
267
272
|
.off('eledata_added eledata_loaded', this._updateChart, this)
|
|
268
273
|
.off('eledata_added eledata_loaded', this._updateSummary, this);
|
|
274
|
+
|
|
275
|
+
this.fire('remove');
|
|
269
276
|
},
|
|
270
277
|
|
|
271
278
|
/**
|
|
@@ -386,8 +393,7 @@ export const Elevation = L.Control.Elevation = L.Control.extend({
|
|
|
386
393
|
* Initialize "L.AlmostOver" integration
|
|
387
394
|
*/
|
|
388
395
|
_initAlmostOverHandler: function(map, layer) {
|
|
389
|
-
|
|
390
|
-
Promise.all([
|
|
396
|
+
return (map && this.options.almostOver && !L.Browser.mobile) ? Promise.all([
|
|
391
397
|
this.import(this.__LGEOMUTIL),
|
|
392
398
|
this.import(this.__LALMOSTOVER)
|
|
393
399
|
]).then(() => {
|
|
@@ -398,81 +404,72 @@ export const Elevation = L.Control.Elevation = L.Control.extend({
|
|
|
398
404
|
.on('almost:move', (e) => this._onMouseMoveLayer(e))
|
|
399
405
|
.on('almost:out', (e) => this._onMouseOut(e));
|
|
400
406
|
}
|
|
401
|
-
});
|
|
407
|
+
}) : Promise.resolve();
|
|
402
408
|
},
|
|
403
409
|
|
|
404
410
|
/**
|
|
405
411
|
* Initialize "L.DistanceMarkers" integration
|
|
406
412
|
*/
|
|
407
|
-
_initDistanceMarkers: function(
|
|
408
|
-
|
|
409
|
-
if (this.options.distanceMarkers) {
|
|
410
|
-
Promise.all([
|
|
411
|
-
this.import(this.__LGEOMUTIL),
|
|
412
|
-
this.import(this.__LDISTANCEM)
|
|
413
|
-
]).then(() => this.options.polyline && layer.addTo(map) && this._circleMarkers.bringToFront());
|
|
414
|
-
} else if (this.options.polyline) {
|
|
415
|
-
layer.addTo(map);
|
|
416
|
-
}
|
|
413
|
+
_initDistanceMarkers: function() {
|
|
414
|
+
return this.options.distanceMarkers ? Promise.all([this.import(this.__LGEOMUTIL), this.import(this.__LDISTANCEM)]) : Promise.resolve();
|
|
417
415
|
},
|
|
418
416
|
|
|
419
|
-
_initHotLine: function(
|
|
420
|
-
this.
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
417
|
+
_initHotLine: function(layer) {
|
|
418
|
+
let prop = typeof this.options.hotline == 'string' ? this.options.hotline : 'elevation';
|
|
419
|
+
return this.options.hotline ? this.import(this.__LHOTLINE)
|
|
420
|
+
.then(() => {
|
|
421
|
+
layer.eachLayer((trkseg) => {
|
|
422
|
+
if(trkseg.feature.geometry.type != "Point") {
|
|
423
|
+
let geo = L.geoJson(trkseg.toGeoJSON(), { coordsToLatLng: (coords) => L.latLng(coords[0], coords[1], coords[2])});
|
|
424
|
+
let line = L.hotline(geo.toGeoJSON().features[0].geometry.coordinates, {
|
|
425
|
+
min: isFinite(this.track_info[prop + '_min']) ? this.track_info[prop + '_min'] : 0,
|
|
426
|
+
max: isFinite(this.track_info[prop + '_max']) ? this.track_info[prop + '_max'] : 1,
|
|
427
|
+
palette: {
|
|
428
|
+
0.0: '#008800',
|
|
429
|
+
0.5: '#ffff00',
|
|
430
|
+
1.0: '#ff0000'
|
|
431
|
+
},
|
|
432
|
+
weight: 5,
|
|
433
|
+
outlineColor: '#000000',
|
|
434
|
+
outlineWidth: 1
|
|
435
|
+
}).addTo(this._hotline);
|
|
436
|
+
let alpha = trkseg.options.style && trkseg.options.style.opacity || 1;
|
|
437
|
+
trkseg.on('add remove', ({type}) => {
|
|
438
|
+
trkseg.setStyle({opacity: (type == 'add' ? 0 : alpha)});
|
|
439
|
+
line[(type == 'add' ? 'addTo' : 'removeFrom')](trkseg._map);
|
|
440
|
+
if (line._renderer) line._renderer._container.parentElement.insertBefore(line._renderer._container, line._renderer._container.parentElement.firstChild);
|
|
441
|
+
});
|
|
442
|
+
}
|
|
427
443
|
});
|
|
428
|
-
});
|
|
429
|
-
let prop = typeof this.options.hotline == 'string' ? this.options.hotline : 'elevation';
|
|
430
|
-
this.import(this.__LHOTLINE)
|
|
431
|
-
.then(() => {
|
|
432
|
-
layer.setStyle({opacity: 0});
|
|
433
|
-
layer.eachLayer((trkseg) => {
|
|
434
|
-
if(trkseg.feature.geometry.type != "Point") {
|
|
435
|
-
let geo = L.geoJson(trkseg.toGeoJSON(), { coordsToLatLng: (coords) => L.latLng(coords[0], coords[1], coords[2])});
|
|
436
|
-
let line = L.hotline(geo.toGeoJSON().features[0].geometry.coordinates, {
|
|
437
|
-
min: isFinite(this.track_info[prop + '_min']) ? this.track_info[prop + '_min'] : 0,
|
|
438
|
-
max: isFinite(this.track_info[prop + '_max']) ? this.track_info[prop + '_max'] : 1,
|
|
439
|
-
palette: {
|
|
440
|
-
0.0: '#008800',
|
|
441
|
-
0.5: '#ffff00',
|
|
442
|
-
1.0: '#ff0000'
|
|
443
|
-
},
|
|
444
|
-
weight: 5,
|
|
445
|
-
outlineColor: '#000000',
|
|
446
|
-
outlineWidth: 1
|
|
447
|
-
}).addTo(this._hotline);
|
|
448
|
-
}
|
|
449
|
-
});
|
|
450
|
-
});
|
|
451
|
-
}
|
|
444
|
+
}) : Promise.resolve();
|
|
452
445
|
},
|
|
453
446
|
|
|
454
447
|
/**
|
|
455
448
|
* Initialize "L.AlmostOver" and "L.DistanceMarkers"
|
|
456
449
|
*/
|
|
457
|
-
_initMapIntegrations: function(
|
|
458
|
-
let map
|
|
459
|
-
if (control._data.length) {
|
|
460
|
-
control._start.setLatLng(control._data[0].latlng);
|
|
461
|
-
control._end.setLatLng(control._data[control._data.length -1].latlng);
|
|
462
|
-
}
|
|
450
|
+
_initMapIntegrations: function(layer) {
|
|
451
|
+
let map = this._map;
|
|
463
452
|
if (map) {
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
control._initHotLine(map, layer);
|
|
468
|
-
control._initAlmostOverHandler(map, layer);
|
|
469
|
-
control._initDistanceMarkers(map, layer);
|
|
470
|
-
} else if (control.options.polyline) {
|
|
471
|
-
layer.addTo(map);
|
|
453
|
+
if (this._data.length) {
|
|
454
|
+
this._start.setLatLng(this._data[0].latlng);
|
|
455
|
+
this._end.setLatLng(this._data[this._data.length -1].latlng);
|
|
472
456
|
}
|
|
473
|
-
|
|
457
|
+
Promise.all([
|
|
458
|
+
this._initHotLine(layer),
|
|
459
|
+
this._initAlmostOverHandler(map, layer),
|
|
460
|
+
this._initDistanceMarkers(),
|
|
461
|
+
]).then(() => {
|
|
462
|
+
if (this.options.polyline) {
|
|
463
|
+
layer.addTo(map);
|
|
464
|
+
this._circleMarkers.addTo(map);
|
|
465
|
+
}
|
|
466
|
+
if (this.options.autofitBounds) {
|
|
467
|
+
this.fitBounds(layer.getBounds());
|
|
468
|
+
}
|
|
469
|
+
map.invalidateSize();
|
|
470
|
+
});
|
|
474
471
|
} else {
|
|
475
|
-
|
|
472
|
+
this.once('add', () => this._initMapIntegrations(layer));
|
|
476
473
|
}
|
|
477
474
|
},
|
|
478
475
|
|
|
@@ -641,6 +638,7 @@ export const Elevation = L.Control.Elevation = L.Control.extend({
|
|
|
641
638
|
this._updateSummary();
|
|
642
639
|
});
|
|
643
640
|
|
|
641
|
+
|
|
644
642
|
},
|
|
645
643
|
|
|
646
644
|
_initLayer: function() {
|
|
@@ -677,12 +675,9 @@ export const Elevation = L.Control.Elevation = L.Control.extend({
|
|
|
677
675
|
* Inspired by L.Control.Layers
|
|
678
676
|
*/
|
|
679
677
|
_initButton: function(container) {
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
.disableClickPropagation(container)
|
|
684
|
-
.disableScrollPropagation(container);
|
|
685
|
-
}
|
|
678
|
+
L.DomEvent
|
|
679
|
+
.disableClickPropagation(container)
|
|
680
|
+
.disableScrollPropagation(container);
|
|
686
681
|
|
|
687
682
|
this.options.collapsed ? this._collapse() : this._expand();
|
|
688
683
|
|
|
@@ -730,7 +725,7 @@ export const Elevation = L.Control.Elevation = L.Control.extend({
|
|
|
730
725
|
// First map known classnames (eg. "Altitude" --> L.Control.Elevation.Altitude)
|
|
731
726
|
handlers = handlers.map((h) => typeof h === 'string' && typeof Elevation[h] !== "undefined" ? Elevation[h] : h);
|
|
732
727
|
// Then load optional classes and custom imports (eg. "Cadence" --> import('../src/handlers/cadence.js'))
|
|
733
|
-
Promise.
|
|
728
|
+
return Promise.
|
|
734
729
|
all(
|
|
735
730
|
handlers
|
|
736
731
|
.filter(h => typeof h === 'string' || h instanceof Promise)
|
|
@@ -792,7 +787,7 @@ export const Elevation = L.Control.Elevation = L.Control.extend({
|
|
|
792
787
|
});
|
|
793
788
|
|
|
794
789
|
this.import(this.__D3).then(() => {
|
|
795
|
-
this._initMapIntegrations(
|
|
790
|
+
this._initMapIntegrations(layer);
|
|
796
791
|
this._fireEvt("eledata_loaded", { data: geojson, layer: layer, name: this.track_info.name, track_info: this.track_info });
|
|
797
792
|
});
|
|
798
793
|
|