@raruto/leaflet-elevation 1.8.6 → 1.8.7
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 +1 -1
- package/dist/leaflet-elevation.js +120 -120
- package/dist/leaflet-elevation.js.map +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/control.js +63 -55
- package/src/index.js +10 -8
package/package.json
CHANGED
package/src/control.js
CHANGED
|
@@ -14,10 +14,10 @@ export const Elevation = L.Control.Elevation = L.Control.extend({
|
|
|
14
14
|
__mileFactor: 0.621371,
|
|
15
15
|
__footFactor: 3.28084,
|
|
16
16
|
__D3: 'https://unpkg.com/d3@6.5.0/dist/d3.min.js',
|
|
17
|
-
__TOGEOJSON: 'https://unpkg.com/@tmcw/togeojson@4.
|
|
17
|
+
__TOGEOJSON: 'https://unpkg.com/@tmcw/togeojson@4.5.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.8.
|
|
20
|
+
__LDISTANCEM: 'https://unpkg.com/@raruto/leaflet-elevation@1.8.7/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
|
|
@@ -304,6 +304,9 @@ export const Elevation = L.Control.Elevation = L.Control.extend({
|
|
|
304
304
|
return;
|
|
305
305
|
}
|
|
306
306
|
|
|
307
|
+
/**
|
|
308
|
+
* Standard GeoJSON --> doesn't handle "time", "heart", …
|
|
309
|
+
*/
|
|
307
310
|
let geom = d.geometry;
|
|
308
311
|
if (geom) {
|
|
309
312
|
switch (geom.type) {
|
|
@@ -319,35 +322,47 @@ export const Elevation = L.Control.Elevation = L.Control.extend({
|
|
|
319
322
|
console.warn('Unsopperted GeoJSON feature geometry type:' + geom.type);
|
|
320
323
|
}
|
|
321
324
|
}
|
|
322
|
-
|
|
323
325
|
if (d.type === "FeatureCollection") {
|
|
324
326
|
_.each(d.features, feature => this._addData(feature));
|
|
325
327
|
}
|
|
326
328
|
|
|
329
|
+
/**
|
|
330
|
+
* Extended GeoJSON --> rely on leaflet implementation
|
|
331
|
+
*/
|
|
327
332
|
if (d._latlngs) {
|
|
328
|
-
this.
|
|
333
|
+
this._addGeoJSONData(d._latlngs, d.feature && d.feature.properties);
|
|
329
334
|
}
|
|
330
335
|
},
|
|
331
336
|
|
|
332
337
|
/*
|
|
333
338
|
* Parsing of GeoJSON data lines and their elevation in z-coordinate
|
|
334
339
|
*/
|
|
335
|
-
_addGeoJSONData: function(coords) {
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
340
|
+
_addGeoJSONData: function(coords, properties) {
|
|
341
|
+
coords.forEach((point, i) => {
|
|
342
|
+
|
|
343
|
+
// Inspired by L.GPX layer properties
|
|
344
|
+
point.meta = point.meta ?? { time: null, ele: null, hr: null, cad: null, atemp: null };
|
|
345
|
+
|
|
346
|
+
// "alt" property is generated inside "leaflet"
|
|
347
|
+
if ("alt" in point) point.meta.ele = point.alt;
|
|
348
|
+
|
|
349
|
+
// "coordinateProperties" property is generated inside "@tmcw/toGeoJSON"
|
|
350
|
+
if (properties.coordinateProperties) {
|
|
351
|
+
let props = properties.coordinateProperties;
|
|
352
|
+
if("times" in props) point.meta.time = new Date(Date.parse(props.times[i]));
|
|
353
|
+
if("heart" in props) point.meta.hr = parseInt(props.heart[i]);
|
|
354
|
+
// TODO: ask to "@tmcw/toGeoJSON" for "cadence" and "temperature" implementation
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
this._addPoint(
|
|
358
|
+
point.lat ?? point[1],
|
|
359
|
+
point.lng ?? point[0],
|
|
360
|
+
point.alt ?? point.meta.ele ?? point[2]
|
|
361
|
+
);
|
|
342
362
|
|
|
343
|
-
/*
|
|
344
|
-
* Parsing function for GPX data and their elevation in z-coordinate
|
|
345
|
-
*/
|
|
346
|
-
_addGPXData: function(coords) {
|
|
347
|
-
_.each(coords, point => {
|
|
348
|
-
this._addPoint(point.lat, point.lng, point.alt ?? point.meta.ele);
|
|
349
363
|
this._fireEvt("elepoint_added", { point: point, index: this._data.length - 1 });
|
|
350
364
|
});
|
|
365
|
+
|
|
351
366
|
this._fireEvt("eletrack_added", { coords: coords, index: this._data.length - 1 });
|
|
352
367
|
},
|
|
353
368
|
|
|
@@ -392,6 +407,9 @@ export const Elevation = L.Control.Elevation = L.Control.extend({
|
|
|
392
407
|
}
|
|
393
408
|
},
|
|
394
409
|
|
|
410
|
+
/**
|
|
411
|
+
* Initialize "L.AlmostOver" integration
|
|
412
|
+
*/
|
|
395
413
|
_initAlmostOverHandler: function(map, layer) {
|
|
396
414
|
if(!map || !this.options.almostOver) return;
|
|
397
415
|
this.lazyLoad(this.__LGEOMUTIL)
|
|
@@ -407,6 +425,9 @@ export const Elevation = L.Control.Elevation = L.Control.extend({
|
|
|
407
425
|
});
|
|
408
426
|
},
|
|
409
427
|
|
|
428
|
+
/**
|
|
429
|
+
* Initialize "L.DistanceMarkers" integration
|
|
430
|
+
*/
|
|
410
431
|
_initDistanceMarkers: function(map, layer) {
|
|
411
432
|
if (!map) return;
|
|
412
433
|
if (this.options.distanceMarkers) {
|
|
@@ -433,6 +454,24 @@ export const Elevation = L.Control.Elevation = L.Control.extend({
|
|
|
433
454
|
return this.eleDiv = eleDiv;
|
|
434
455
|
},
|
|
435
456
|
|
|
457
|
+
/**
|
|
458
|
+
* Initialize "L.AlmostOver" and "L.DistanceMarkers"
|
|
459
|
+
*/
|
|
460
|
+
_initMapIntegrations: function(control, layer) {
|
|
461
|
+
let map = control._map;
|
|
462
|
+
if (control._map) {
|
|
463
|
+
map.once('layeradd', (e) => control.options.autofitBounds && control.fitBounds(layer.getBounds()));
|
|
464
|
+
if (!L.Browser.mobile) {
|
|
465
|
+
control._initAlmostOverHandler(map, layer);
|
|
466
|
+
control._initDistanceMarkers(map, layer);
|
|
467
|
+
} else if (control.options.polyline) {
|
|
468
|
+
layer.addTo(map);
|
|
469
|
+
}
|
|
470
|
+
} else {
|
|
471
|
+
console.warn("Undefined elevation map object");;
|
|
472
|
+
}
|
|
473
|
+
},
|
|
474
|
+
|
|
436
475
|
/*
|
|
437
476
|
* Collapse current chart control.
|
|
438
477
|
*/
|
|
@@ -720,46 +759,15 @@ export const Elevation = L.Control.Elevation = L.Control.extend({
|
|
|
720
759
|
}
|
|
721
760
|
},
|
|
722
761
|
onEachFeature: (feature, layer) => {
|
|
723
|
-
if (feature.geometry && feature.geometry.type
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
// Extended GeoJSON --> rely on leaflet implementation
|
|
729
|
-
layer._latlngs.forEach((point, i) => {
|
|
730
|
-
// same properties as L.GPX layer
|
|
731
|
-
point.meta = { time: null, ele: null, hr: null, cad: null, atemp: null };
|
|
732
|
-
if("alt" in point) point.meta.ele = point.alt;
|
|
733
|
-
if(feature.properties) {
|
|
734
|
-
let prop = feature.properties;
|
|
735
|
-
if("coordTimes" in prop) point.meta.time = new Date(Date.parse(prop.coordTimes[i]));
|
|
736
|
-
else if("times" in prop) point.meta.time = new Date(Date.parse(prop.times[i]));
|
|
737
|
-
else if("time" in prop) point.meta.time = new Date(Date.parse((typeof prop.time === 'object' ? prop.time[i] : prop.time)));
|
|
738
|
-
if("heartRates" in prop) point.meta.hr = parseInt(prop.heartRates[i]);
|
|
739
|
-
else if("heartRate" in prop) point.meta.hr = parseInt((typeof prop.heartRate === 'object' ? prop.heartRate[i] : prop.heartRate));
|
|
740
|
-
// TODO: cadence, temperature
|
|
741
|
-
}
|
|
742
|
-
});
|
|
743
|
-
control.addData(layer); // NB make use of "_addGPXData"
|
|
744
|
-
|
|
745
|
-
control.track_info = L.extend({}, control.track_info, { name: geojson.name });
|
|
762
|
+
if (feature.geometry && feature.geometry.type != 'Point') {
|
|
763
|
+
control.addData(layer);
|
|
764
|
+
control.track_info = L.extend({}, control.track_info, { name: geojson.name });
|
|
765
|
+
}
|
|
746
766
|
},
|
|
747
767
|
});
|
|
748
768
|
|
|
749
769
|
control.lazyLoad(control.__D3).then(() => {
|
|
750
|
-
|
|
751
|
-
if (map) {
|
|
752
|
-
map.once('layeradd', (e) => control.options.autofitBounds && control.fitBounds(layer.getBounds()));
|
|
753
|
-
if (!L.Browser.mobile) {
|
|
754
|
-
control._initAlmostOverHandler(map, layer);
|
|
755
|
-
control._initDistanceMarkers(map, layer);
|
|
756
|
-
} else if (control.options.polyline) {
|
|
757
|
-
layer.addTo(map);
|
|
758
|
-
}
|
|
759
|
-
} else {
|
|
760
|
-
console.warn("Undefined elevation map object");;
|
|
761
|
-
}
|
|
762
|
-
|
|
770
|
+
control._initMapIntegrations(control, layer);
|
|
763
771
|
control._fireEvt("eledata_loaded", { data: geojson, layer: layer, name: control.track_info.name, track_info: control.track_info })
|
|
764
772
|
});
|
|
765
773
|
|
|
@@ -889,7 +897,7 @@ export const Elevation = L.Control.Elevation = L.Control.extend({
|
|
|
889
897
|
/**
|
|
890
898
|
* Extend GeoJSON properties (name, time, ...)
|
|
891
899
|
*/
|
|
892
|
-
_prepareAdditionalProperties: function(geojson){
|
|
900
|
+
_prepareAdditionalProperties: function(geojson) {
|
|
893
901
|
if (!geojson.name && this._downloadURL) {
|
|
894
902
|
geojson.name = this._downloadURL.split('/').pop().split('#')[0].split('?')[0];
|
|
895
903
|
}
|
|
@@ -948,7 +956,7 @@ export const Elevation = L.Control.Elevation = L.Control.extend({
|
|
|
948
956
|
/**
|
|
949
957
|
* Add chart or marker tooltip info
|
|
950
958
|
*/
|
|
951
|
-
|
|
959
|
+
_registerTooltip: function(props) {
|
|
952
960
|
if (props.chart) {
|
|
953
961
|
let label = L.extend({}, props, { value: props.chart });
|
|
954
962
|
this.on("elechart_init", () => this._chart._registerTooltip(label));
|
package/src/index.js
CHANGED
|
@@ -63,14 +63,16 @@ Elevation.Chart = Chart;
|
|
|
63
63
|
|
|
64
64
|
// Alias deprecated functions
|
|
65
65
|
Elevation.addInitHook(function() {
|
|
66
|
-
this.enableDragging
|
|
67
|
-
this.disableDragging
|
|
68
|
-
this.loadChart
|
|
69
|
-
this.loadData
|
|
70
|
-
this.loadGPX
|
|
71
|
-
this.loadGeoJSON
|
|
72
|
-
this.loadXML
|
|
73
|
-
this.loadFile
|
|
66
|
+
this.enableDragging = this.enableBrush;
|
|
67
|
+
this.disableDragging = this.disableBrush;
|
|
68
|
+
this.loadChart = this.addTo;
|
|
69
|
+
this.loadData = this.load;
|
|
70
|
+
this.loadGPX = this.load;
|
|
71
|
+
this.loadGeoJSON = this.load;
|
|
72
|
+
this.loadXML = this.load;
|
|
73
|
+
this.loadFile = this.load;
|
|
74
|
+
this._addGPXData = this._addGeoJSONData;
|
|
75
|
+
this._registerFocusLabel = this._registerTooltip;
|
|
74
76
|
});
|
|
75
77
|
|
|
76
78
|
L.control.elevation = (options) => new Elevation(options);
|