@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.
- package/dist/leaflet-elevation.js +79 -43
- package/dist/leaflet-elevation.js.map +1 -1
- package/dist/leaflet-elevation.min.js +1 -1
- package/dist/leaflet-elevation.min.js.map +1 -1
- package/libs/leaflet-hotline.js +457 -0
- package/libs/leaflet-hotline.min.js +1 -0
- package/package.json +1 -1
- package/src/control.js +77 -43
- package/src/options.js +1 -0
package/src/control.js
CHANGED
|
@@ -13,6 +13,7 @@ export const Elevation = L.Control.Elevation = L.Control.extend({
|
|
|
13
13
|
__TOGEOJSON: 'https://unpkg.com/@tmcw/togeojson@4.6.0/dist/togeojson.umd.js',
|
|
14
14
|
__LGEOMUTIL: 'https://unpkg.com/leaflet-geometryutil@0.9.3/src/leaflet.geometryutil.js',
|
|
15
15
|
__LALMOSTOVER: 'https://unpkg.com/leaflet-almostover@1.0.1/src/leaflet.almostover.js',
|
|
16
|
+
__LHOTLINE: '../libs/leaflet-hotline.min.js',
|
|
16
17
|
__LDISTANCEM: '../libs/leaflet-distance-marker.min.js',
|
|
17
18
|
__LCHART: '../src/components/chart.js',
|
|
18
19
|
__LMARKER: '../src/components/marker.js',
|
|
@@ -54,7 +55,8 @@ export const Elevation = L.Control.Elevation = L.Control.extend({
|
|
|
54
55
|
if (this._chart) this._clearChart();
|
|
55
56
|
if (this._layers) this._clearLayers(this._layers);
|
|
56
57
|
if (this._markers) this._clearLayers(this._markers);
|
|
57
|
-
if (this._circleMarkers) this.
|
|
58
|
+
if (this._circleMarkers) this._circleMarkers.remove();
|
|
59
|
+
if (this._hotline) this._clearLayers(this._hotline);
|
|
58
60
|
|
|
59
61
|
this._data = [];
|
|
60
62
|
this.track_info = {};
|
|
@@ -164,6 +166,7 @@ export const Elevation = L.Control.Elevation = L.Control.extend({
|
|
|
164
166
|
this._data = [];
|
|
165
167
|
this._layers = L.featureGroup();
|
|
166
168
|
this._markers = L.featureGroup();
|
|
169
|
+
this._hotline = L.featureGroup();
|
|
167
170
|
this._circleMarkers = L.featureGroup();
|
|
168
171
|
this._markedSegments = L.polyline([]);
|
|
169
172
|
this._start = (opts.trkStart || Options.trkStart);
|
|
@@ -235,12 +238,15 @@ export const Elevation = L.Control.Elevation = L.Control.extend({
|
|
|
235
238
|
...this.options.handlers
|
|
236
239
|
].filter(m => false !== this.options[typeof m == "string" && m.toLowerCase()]);
|
|
237
240
|
|
|
238
|
-
this._loadModules(modules)
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
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');
|
|
244
250
|
|
|
245
251
|
return container;
|
|
246
252
|
},
|
|
@@ -265,6 +271,8 @@ export const Elevation = L.Control.Elevation = L.Control.extend({
|
|
|
265
271
|
this
|
|
266
272
|
.off('eledata_added eledata_loaded', this._updateChart, this)
|
|
267
273
|
.off('eledata_added eledata_loaded', this._updateSummary, this);
|
|
274
|
+
|
|
275
|
+
this.fire('remove');
|
|
268
276
|
},
|
|
269
277
|
|
|
270
278
|
/**
|
|
@@ -385,8 +393,7 @@ export const Elevation = L.Control.Elevation = L.Control.extend({
|
|
|
385
393
|
* Initialize "L.AlmostOver" integration
|
|
386
394
|
*/
|
|
387
395
|
_initAlmostOverHandler: function(map, layer) {
|
|
388
|
-
|
|
389
|
-
Promise.all([
|
|
396
|
+
return (map && this.options.almostOver && !L.Browser.mobile) ? Promise.all([
|
|
390
397
|
this.import(this.__LGEOMUTIL),
|
|
391
398
|
this.import(this.__LALMOSTOVER)
|
|
392
399
|
]).then(() => {
|
|
@@ -397,45 +404,72 @@ export const Elevation = L.Control.Elevation = L.Control.extend({
|
|
|
397
404
|
.on('almost:move', (e) => this._onMouseMoveLayer(e))
|
|
398
405
|
.on('almost:out', (e) => this._onMouseOut(e));
|
|
399
406
|
}
|
|
400
|
-
});
|
|
407
|
+
}) : Promise.resolve();
|
|
401
408
|
},
|
|
402
409
|
|
|
403
410
|
/**
|
|
404
411
|
* Initialize "L.DistanceMarkers" integration
|
|
405
412
|
*/
|
|
406
|
-
_initDistanceMarkers: function(
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
413
|
+
_initDistanceMarkers: function() {
|
|
414
|
+
return this.options.distanceMarkers ? Promise.all([this.import(this.__LGEOMUTIL), this.import(this.__LDISTANCEM)]) : Promise.resolve();
|
|
415
|
+
},
|
|
416
|
+
|
|
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
|
+
}
|
|
443
|
+
});
|
|
444
|
+
}) : Promise.resolve();
|
|
416
445
|
},
|
|
417
446
|
|
|
418
447
|
/**
|
|
419
448
|
* Initialize "L.AlmostOver" and "L.DistanceMarkers"
|
|
420
449
|
*/
|
|
421
|
-
_initMapIntegrations: function(
|
|
422
|
-
let map
|
|
423
|
-
if (control._data.length) {
|
|
424
|
-
control._start.setLatLng(control._data[0].latlng);
|
|
425
|
-
control._end.setLatLng(control._data[control._data.length -1].latlng);
|
|
426
|
-
}
|
|
450
|
+
_initMapIntegrations: function(layer) {
|
|
451
|
+
let map = this._map;
|
|
427
452
|
if (map) {
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
control._initAlmostOverHandler(map, layer);
|
|
432
|
-
control._initDistanceMarkers(map, layer);
|
|
433
|
-
} else if (control.options.polyline) {
|
|
434
|
-
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);
|
|
435
456
|
}
|
|
436
|
-
|
|
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
|
+
});
|
|
437
471
|
} else {
|
|
438
|
-
|
|
472
|
+
this.once('add', () => this._initMapIntegrations(layer));
|
|
439
473
|
}
|
|
440
474
|
},
|
|
441
475
|
|
|
@@ -444,6 +478,7 @@ export const Elevation = L.Control.Elevation = L.Control.extend({
|
|
|
444
478
|
*/
|
|
445
479
|
_collapse: function() {
|
|
446
480
|
_.replaceClass(this._container, 'elevation-expanded', 'elevation-collapsed');
|
|
481
|
+
if (this._map) this._map.invalidateSize();
|
|
447
482
|
},
|
|
448
483
|
|
|
449
484
|
/*
|
|
@@ -451,6 +486,7 @@ export const Elevation = L.Control.Elevation = L.Control.extend({
|
|
|
451
486
|
*/
|
|
452
487
|
_expand: function() {
|
|
453
488
|
_.replaceClass(this._container, 'elevation-collapsed', 'elevation-expanded');
|
|
489
|
+
if (this._map) this._map.invalidateSize();
|
|
454
490
|
},
|
|
455
491
|
|
|
456
492
|
/**
|
|
@@ -602,6 +638,7 @@ export const Elevation = L.Control.Elevation = L.Control.extend({
|
|
|
602
638
|
this._updateSummary();
|
|
603
639
|
});
|
|
604
640
|
|
|
641
|
+
|
|
605
642
|
},
|
|
606
643
|
|
|
607
644
|
_initLayer: function() {
|
|
@@ -638,12 +675,9 @@ export const Elevation = L.Control.Elevation = L.Control.extend({
|
|
|
638
675
|
* Inspired by L.Control.Layers
|
|
639
676
|
*/
|
|
640
677
|
_initButton: function(container) {
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
.disableClickPropagation(container)
|
|
645
|
-
.disableScrollPropagation(container);
|
|
646
|
-
}
|
|
678
|
+
L.DomEvent
|
|
679
|
+
.disableClickPropagation(container)
|
|
680
|
+
.disableScrollPropagation(container);
|
|
647
681
|
|
|
648
682
|
this.options.collapsed ? this._collapse() : this._expand();
|
|
649
683
|
|
|
@@ -691,7 +725,7 @@ export const Elevation = L.Control.Elevation = L.Control.extend({
|
|
|
691
725
|
// First map known classnames (eg. "Altitude" --> L.Control.Elevation.Altitude)
|
|
692
726
|
handlers = handlers.map((h) => typeof h === 'string' && typeof Elevation[h] !== "undefined" ? Elevation[h] : h);
|
|
693
727
|
// Then load optional classes and custom imports (eg. "Cadence" --> import('../src/handlers/cadence.js'))
|
|
694
|
-
Promise.
|
|
728
|
+
return Promise.
|
|
695
729
|
all(
|
|
696
730
|
handlers
|
|
697
731
|
.filter(h => typeof h === 'string' || h instanceof Promise)
|
|
@@ -753,7 +787,7 @@ export const Elevation = L.Control.Elevation = L.Control.extend({
|
|
|
753
787
|
});
|
|
754
788
|
|
|
755
789
|
this.import(this.__D3).then(() => {
|
|
756
|
-
this._initMapIntegrations(
|
|
790
|
+
this._initMapIntegrations(layer);
|
|
757
791
|
this._fireEvt("eledata_loaded", { data: geojson, layer: layer, name: this.track_info.name, track_info: this.track_info });
|
|
758
792
|
});
|
|
759
793
|
|