@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.
|
@@ -380,7 +380,8 @@
|
|
|
380
380
|
if (this._chart) this._clearChart();
|
|
381
381
|
if (this._layers) this._clearLayers(this._layers);
|
|
382
382
|
if (this._markers) this._clearLayers(this._markers);
|
|
383
|
-
if (this._circleMarkers) this.
|
|
383
|
+
if (this._circleMarkers) this._circleMarkers.remove();
|
|
384
|
+
if (this._hotline) this._clearLayers(this._hotline);
|
|
384
385
|
|
|
385
386
|
this._data = [];
|
|
386
387
|
this.track_info = {};
|
|
@@ -490,6 +491,7 @@
|
|
|
490
491
|
this._data = [];
|
|
491
492
|
this._layers = L.featureGroup();
|
|
492
493
|
this._markers = L.featureGroup();
|
|
494
|
+
this._hotline = L.featureGroup();
|
|
493
495
|
this._circleMarkers = L.featureGroup();
|
|
494
496
|
this._markedSegments = L.polyline([]);
|
|
495
497
|
this._start = (opts.trkStart || Options.trkStart);
|
|
@@ -561,12 +563,15 @@
|
|
|
561
563
|
...this.options.handlers
|
|
562
564
|
].filter(m => false !== this.options[typeof m == "string" && m.toLowerCase()]);
|
|
563
565
|
|
|
564
|
-
this._loadModules(modules)
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
566
|
+
this._loadModules(modules).then(() => { // Inject here required modules (data handlers)
|
|
567
|
+
this._initChart(container);
|
|
568
|
+
this._initButton(container);
|
|
569
|
+
this._initSummary(container);
|
|
570
|
+
this._initMarker(map);
|
|
571
|
+
this._initLayer(map);
|
|
572
|
+
});
|
|
573
|
+
|
|
574
|
+
this.fire('add');
|
|
570
575
|
|
|
571
576
|
return container;
|
|
572
577
|
},
|
|
@@ -591,6 +596,8 @@
|
|
|
591
596
|
this
|
|
592
597
|
.off('eledata_added eledata_loaded', this._updateChart, this)
|
|
593
598
|
.off('eledata_added eledata_loaded', this._updateSummary, this);
|
|
599
|
+
|
|
600
|
+
this.fire('remove');
|
|
594
601
|
},
|
|
595
602
|
|
|
596
603
|
/**
|
|
@@ -711,8 +718,7 @@
|
|
|
711
718
|
* Initialize "L.AlmostOver" integration
|
|
712
719
|
*/
|
|
713
720
|
_initAlmostOverHandler: function(map, layer) {
|
|
714
|
-
|
|
715
|
-
Promise.all([
|
|
721
|
+
return (map && this.options.almostOver && !L.Browser.mobile) ? Promise.all([
|
|
716
722
|
this.import(this.__LGEOMUTIL),
|
|
717
723
|
this.import(this.__LALMOSTOVER)
|
|
718
724
|
]).then(() => {
|
|
@@ -723,81 +729,73 @@
|
|
|
723
729
|
.on('almost:move', (e) => this._onMouseMoveLayer(e))
|
|
724
730
|
.on('almost:out', (e) => this._onMouseOut(e));
|
|
725
731
|
}
|
|
726
|
-
});
|
|
732
|
+
}) : Promise.resolve();
|
|
727
733
|
},
|
|
728
734
|
|
|
729
735
|
/**
|
|
730
736
|
* Initialize "L.DistanceMarkers" integration
|
|
731
737
|
*/
|
|
732
|
-
_initDistanceMarkers: function(
|
|
733
|
-
|
|
734
|
-
if (this.options.distanceMarkers) {
|
|
735
|
-
Promise.all([
|
|
736
|
-
this.import(this.__LGEOMUTIL),
|
|
737
|
-
this.import(this.__LDISTANCEM)
|
|
738
|
-
]).then(() => this.options.polyline && layer.addTo(map) && this._circleMarkers.bringToFront());
|
|
739
|
-
} else if (this.options.polyline) {
|
|
740
|
-
layer.addTo(map);
|
|
741
|
-
}
|
|
738
|
+
_initDistanceMarkers: function() {
|
|
739
|
+
return this.options.distanceMarkers ? Promise.all([this.import(this.__LGEOMUTIL), this.import(this.__LDISTANCEM)]) : Promise.resolve();
|
|
742
740
|
},
|
|
743
741
|
|
|
744
|
-
_initHotLine: function(
|
|
745
|
-
this.
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
742
|
+
_initHotLine: function(layer) {
|
|
743
|
+
let prop = typeof this.options.hotline == 'string' ? this.options.hotline : 'elevation';
|
|
744
|
+
return this.options.hotline ? this.import(this.__LHOTLINE)
|
|
745
|
+
.then(() => {
|
|
746
|
+
layer.eachLayer((trkseg) => {
|
|
747
|
+
if(trkseg.feature.geometry.type != "Point") {
|
|
748
|
+
let geo = L.geoJson(trkseg.toGeoJSON(), { coordsToLatLng: (coords) => L.latLng(coords[0], coords[1], coords[2])});
|
|
749
|
+
let line = L.hotline(geo.toGeoJSON().features[0].geometry.coordinates, {
|
|
750
|
+
min: isFinite(this.track_info[prop + '_min']) ? this.track_info[prop + '_min'] : 0,
|
|
751
|
+
max: isFinite(this.track_info[prop + '_max']) ? this.track_info[prop + '_max'] : 1,
|
|
752
|
+
palette: {
|
|
753
|
+
0.0: '#008800',
|
|
754
|
+
0.5: '#ffff00',
|
|
755
|
+
1.0: '#ff0000'
|
|
756
|
+
},
|
|
757
|
+
weight: 5,
|
|
758
|
+
outlineColor: '#000000',
|
|
759
|
+
outlineWidth: 1
|
|
760
|
+
}).addTo(this._hotline);
|
|
761
|
+
let alpha = trkseg.options.style && trkseg.options.style.opacity || 1;
|
|
762
|
+
trkseg.on('add remove', ({type}) => {
|
|
763
|
+
trkseg.setStyle({opacity: (type == 'add' ? 0 : alpha)});
|
|
764
|
+
line[(type == 'add' ? 'addTo' : 'removeFrom')](trkseg._map);
|
|
765
|
+
if (line._renderer) line._renderer._container.parentElement.insertBefore(line._renderer._container, line._renderer._container.parentElement.firstChild);
|
|
766
|
+
});
|
|
767
|
+
}
|
|
752
768
|
});
|
|
753
|
-
});
|
|
754
|
-
let prop = typeof this.options.hotline == 'string' ? this.options.hotline : 'elevation';
|
|
755
|
-
this.import(this.__LHOTLINE)
|
|
756
|
-
.then(() => {
|
|
757
|
-
layer.setStyle({opacity: 0});
|
|
758
|
-
layer.eachLayer((trkseg) => {
|
|
759
|
-
if(trkseg.feature.geometry.type != "Point") {
|
|
760
|
-
let geo = L.geoJson(trkseg.toGeoJSON(), { coordsToLatLng: (coords) => L.latLng(coords[0], coords[1], coords[2])});
|
|
761
|
-
L.hotline(geo.toGeoJSON().features[0].geometry.coordinates, {
|
|
762
|
-
min: isFinite(this.track_info[prop + '_min']) ? this.track_info[prop + '_min'] : 0,
|
|
763
|
-
max: isFinite(this.track_info[prop + '_max']) ? this.track_info[prop + '_max'] : 1,
|
|
764
|
-
palette: {
|
|
765
|
-
0.0: '#008800',
|
|
766
|
-
0.5: '#ffff00',
|
|
767
|
-
1.0: '#ff0000'
|
|
768
|
-
},
|
|
769
|
-
weight: 5,
|
|
770
|
-
outlineColor: '#000000',
|
|
771
|
-
outlineWidth: 1
|
|
772
|
-
}).addTo(this._hotline);
|
|
773
|
-
}
|
|
774
|
-
});
|
|
775
|
-
});
|
|
776
|
-
}
|
|
769
|
+
}) : Promise.resolve();
|
|
777
770
|
},
|
|
778
771
|
|
|
779
772
|
/**
|
|
780
773
|
* Initialize "L.AlmostOver" and "L.DistanceMarkers"
|
|
781
774
|
*/
|
|
782
|
-
_initMapIntegrations: function(
|
|
783
|
-
let map
|
|
784
|
-
if (control._data.length) {
|
|
785
|
-
control._start.setLatLng(control._data[0].latlng);
|
|
786
|
-
control._end.setLatLng(control._data[control._data.length -1].latlng);
|
|
787
|
-
}
|
|
775
|
+
_initMapIntegrations: function(layer) {
|
|
776
|
+
let map = this._map;
|
|
788
777
|
if (map) {
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
control._initHotLine(map, layer);
|
|
793
|
-
control._initAlmostOverHandler(map, layer);
|
|
794
|
-
control._initDistanceMarkers(map, layer);
|
|
795
|
-
} else if (control.options.polyline) {
|
|
796
|
-
layer.addTo(map);
|
|
778
|
+
if (this._data.length) {
|
|
779
|
+
this._start.setLatLng(this._data[0].latlng);
|
|
780
|
+
this._end.setLatLng(this._data[this._data.length -1].latlng);
|
|
797
781
|
}
|
|
798
|
-
|
|
782
|
+
Promise.all([
|
|
783
|
+
this._initHotLine(layer),
|
|
784
|
+
this._initAlmostOverHandler(map, layer),
|
|
785
|
+
this._initDistanceMarkers(),
|
|
786
|
+
]).then(() => {
|
|
787
|
+
if (this.options.polyline) {
|
|
788
|
+
layer.addTo(map);
|
|
789
|
+
this._circleMarkers.addTo(map);
|
|
790
|
+
}
|
|
791
|
+
if (this.options.autofitBounds) {
|
|
792
|
+
this.fitBounds(layer.getBounds());
|
|
793
|
+
}
|
|
794
|
+
map.invalidateSize();
|
|
795
|
+
});
|
|
799
796
|
} else {
|
|
800
|
-
|
|
797
|
+
this.once('add', () => this._initMapIntegrations(layer));
|
|
798
|
+
}
|
|
801
799
|
},
|
|
802
800
|
|
|
803
801
|
/*
|
|
@@ -965,6 +963,7 @@
|
|
|
965
963
|
this._updateSummary();
|
|
966
964
|
});
|
|
967
965
|
|
|
966
|
+
|
|
968
967
|
},
|
|
969
968
|
|
|
970
969
|
_initLayer: function() {
|
|
@@ -1001,12 +1000,9 @@
|
|
|
1001
1000
|
* Inspired by L.Control.Layers
|
|
1002
1001
|
*/
|
|
1003
1002
|
_initButton: function(container) {
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
.disableClickPropagation(container)
|
|
1008
|
-
.disableScrollPropagation(container);
|
|
1009
|
-
}
|
|
1003
|
+
L.DomEvent
|
|
1004
|
+
.disableClickPropagation(container)
|
|
1005
|
+
.disableScrollPropagation(container);
|
|
1010
1006
|
|
|
1011
1007
|
this.options.collapsed ? this._collapse() : this._expand();
|
|
1012
1008
|
|
|
@@ -1054,7 +1050,7 @@
|
|
|
1054
1050
|
// First map known classnames (eg. "Altitude" --> L.Control.Elevation.Altitude)
|
|
1055
1051
|
handlers = handlers.map((h) => typeof h === 'string' && typeof Elevation[h] !== "undefined" ? Elevation[h] : h);
|
|
1056
1052
|
// Then load optional classes and custom imports (eg. "Cadence" --> import('../src/handlers/cadence.js'))
|
|
1057
|
-
Promise.
|
|
1053
|
+
return Promise.
|
|
1058
1054
|
all(
|
|
1059
1055
|
handlers
|
|
1060
1056
|
.filter(h => typeof h === 'string' || h instanceof Promise)
|
|
@@ -1116,7 +1112,7 @@
|
|
|
1116
1112
|
});
|
|
1117
1113
|
|
|
1118
1114
|
this.import(this.__D3).then(() => {
|
|
1119
|
-
this._initMapIntegrations(
|
|
1115
|
+
this._initMapIntegrations(layer);
|
|
1120
1116
|
this._fireEvt("eledata_loaded", { data: geojson, layer: layer, name: this.track_info.name, track_info: this.track_info });
|
|
1121
1117
|
});
|
|
1122
1118
|
|