@raruto/leaflet-elevation 2.0.5 → 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.
@@ -261,6 +261,7 @@
261
261
  imperial: false,
262
262
  legend: true,
263
263
  handlers: [],
264
+ hotline: 'elevation',
264
265
  marker: 'elevation-line',
265
266
  markerIcon: L.divIcon({
266
267
  className: 'elevation-position-marker',
@@ -337,6 +338,7 @@
337
338
  __TOGEOJSON: 'https://unpkg.com/@tmcw/togeojson@4.6.0/dist/togeojson.umd.js',
338
339
  __LGEOMUTIL: 'https://unpkg.com/leaflet-geometryutil@0.9.3/src/leaflet.geometryutil.js',
339
340
  __LALMOSTOVER: 'https://unpkg.com/leaflet-almostover@1.0.1/src/leaflet.almostover.js',
341
+ __LHOTLINE: '../libs/leaflet-hotline.min.js',
340
342
  __LDISTANCEM: '../libs/leaflet-distance-marker.min.js',
341
343
  __LCHART: '../src/components/chart.js',
342
344
  __LMARKER: '../src/components/marker.js',
@@ -378,7 +380,8 @@
378
380
  if (this._chart) this._clearChart();
379
381
  if (this._layers) this._clearLayers(this._layers);
380
382
  if (this._markers) this._clearLayers(this._markers);
381
- if (this._circleMarkers) this._clearLayers(this._circleMarkers);
383
+ if (this._circleMarkers) this._circleMarkers.remove();
384
+ if (this._hotline) this._clearLayers(this._hotline);
382
385
 
383
386
  this._data = [];
384
387
  this.track_info = {};
@@ -488,6 +491,7 @@
488
491
  this._data = [];
489
492
  this._layers = L.featureGroup();
490
493
  this._markers = L.featureGroup();
494
+ this._hotline = L.featureGroup();
491
495
  this._circleMarkers = L.featureGroup();
492
496
  this._markedSegments = L.polyline([]);
493
497
  this._start = (opts.trkStart || Options.trkStart);
@@ -559,12 +563,15 @@
559
563
  ...this.options.handlers
560
564
  ].filter(m => false !== this.options[typeof m == "string" && m.toLowerCase()]);
561
565
 
562
- this._loadModules(modules); // Inject here required modules (data handlers)
563
- this._initButton(container);
564
- this._initChart(container);
565
- this._initSummary(container);
566
- this._initMarker(map);
567
- this._initLayer(map);
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');
568
575
 
569
576
  return container;
570
577
  },
@@ -589,6 +596,8 @@
589
596
  this
590
597
  .off('eledata_added eledata_loaded', this._updateChart, this)
591
598
  .off('eledata_added eledata_loaded', this._updateSummary, this);
599
+
600
+ this.fire('remove');
592
601
  },
593
602
 
594
603
  /**
@@ -709,8 +718,7 @@
709
718
  * Initialize "L.AlmostOver" integration
710
719
  */
711
720
  _initAlmostOverHandler: function(map, layer) {
712
- if(!map || !this.options.almostOver) return;
713
- Promise.all([
721
+ return (map && this.options.almostOver && !L.Browser.mobile) ? Promise.all([
714
722
  this.import(this.__LGEOMUTIL),
715
723
  this.import(this.__LALMOSTOVER)
716
724
  ]).then(() => {
@@ -721,45 +729,73 @@
721
729
  .on('almost:move', (e) => this._onMouseMoveLayer(e))
722
730
  .on('almost:out', (e) => this._onMouseOut(e));
723
731
  }
724
- });
732
+ }) : Promise.resolve();
725
733
  },
726
734
 
727
735
  /**
728
736
  * Initialize "L.DistanceMarkers" integration
729
737
  */
730
- _initDistanceMarkers: function(map, layer) {
731
- if (!map) return;
732
- if (this.options.distanceMarkers) {
733
- Promise.all([
734
- this.import(this.__LGEOMUTIL),
735
- this.import(this.__LDISTANCEM)
736
- ]).then(() => this.options.polyline && layer.addTo(map) && this._circleMarkers.bringToFront());
737
- } else if (this.options.polyline) {
738
- layer.addTo(map);
739
- }
738
+ _initDistanceMarkers: function() {
739
+ return this.options.distanceMarkers ? Promise.all([this.import(this.__LGEOMUTIL), this.import(this.__LDISTANCEM)]) : Promise.resolve();
740
+ },
741
+
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
+ }
768
+ });
769
+ }) : Promise.resolve();
740
770
  },
741
771
 
742
772
  /**
743
773
  * Initialize "L.AlmostOver" and "L.DistanceMarkers"
744
774
  */
745
- _initMapIntegrations: function(control, layer) {
746
- let map = control._map;
747
- if (control._data.length) {
748
- control._start.setLatLng(control._data[0].latlng);
749
- control._end.setLatLng(control._data[control._data.length -1].latlng);
750
- }
775
+ _initMapIntegrations: function(layer) {
776
+ let map = this._map;
751
777
  if (map) {
752
- control._circleMarkers.addTo(map);
753
- map.once('layeradd', (e) => control.options.autofitBounds && control.fitBounds(layer.getBounds()));
754
- if (!L.Browser.mobile) {
755
- control._initAlmostOverHandler(map, layer);
756
- control._initDistanceMarkers(map, layer);
757
- } else if (control.options.polyline) {
758
- 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);
759
781
  }
760
- map.invalidateSize();
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
+ });
761
796
  } else {
762
- console.warn("Undefined elevation map object"); }
797
+ this.once('add', () => this._initMapIntegrations(layer));
798
+ }
763
799
  },
764
800
 
765
801
  /*
@@ -767,6 +803,7 @@
767
803
  */
768
804
  _collapse: function() {
769
805
  replaceClass(this._container, 'elevation-expanded', 'elevation-collapsed');
806
+ if (this._map) this._map.invalidateSize();
770
807
  },
771
808
 
772
809
  /*
@@ -774,6 +811,7 @@
774
811
  */
775
812
  _expand: function() {
776
813
  replaceClass(this._container, 'elevation-collapsed', 'elevation-expanded');
814
+ if (this._map) this._map.invalidateSize();
777
815
  },
778
816
 
779
817
  /**
@@ -925,6 +963,7 @@
925
963
  this._updateSummary();
926
964
  });
927
965
 
966
+
928
967
  },
929
968
 
930
969
  _initLayer: function() {
@@ -961,12 +1000,9 @@
961
1000
  * Inspired by L.Control.Layers
962
1001
  */
963
1002
  _initButton: function(container) {
964
-
965
- if (L.Browser.mobile || !this.options.detached) {
966
- L.DomEvent
967
- .disableClickPropagation(container)
968
- .disableScrollPropagation(container);
969
- }
1003
+ L.DomEvent
1004
+ .disableClickPropagation(container)
1005
+ .disableScrollPropagation(container);
970
1006
 
971
1007
  this.options.collapsed ? this._collapse() : this._expand();
972
1008
 
@@ -1014,7 +1050,7 @@
1014
1050
  // First map known classnames (eg. "Altitude" --> L.Control.Elevation.Altitude)
1015
1051
  handlers = handlers.map((h) => typeof h === 'string' && typeof Elevation[h] !== "undefined" ? Elevation[h] : h);
1016
1052
  // Then load optional classes and custom imports (eg. "Cadence" --> import('../src/handlers/cadence.js'))
1017
- Promise.
1053
+ return Promise.
1018
1054
  all(
1019
1055
  handlers
1020
1056
  .filter(h => typeof h === 'string' || h instanceof Promise)
@@ -1076,7 +1112,7 @@
1076
1112
  });
1077
1113
 
1078
1114
  this.import(this.__D3).then(() => {
1079
- this._initMapIntegrations(this, layer);
1115
+ this._initMapIntegrations(layer);
1080
1116
  this._fireEvt("eledata_loaded", { data: geojson, layer: layer, name: this.track_info.name, track_info: this.track_info });
1081
1117
  });
1082
1118