@raruto/leaflet-elevation 2.5.0 → 2.5.1
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/package.json +2 -2
- package/src/handlers/distance.js +46 -46
- package/src/handlers/temperature.js +62 -0
package/README.md
CHANGED
|
@@ -42,7 +42,7 @@ _For a working example see one of the following demos:_
|
|
|
42
42
|
- [edge scale control](https://raruto.github.io/leaflet-elevation/examples/leaflet-elevation_edge-scale.html)
|
|
43
43
|
- [follow marker](https://raruto.github.io/leaflet-elevation/examples/leaflet-elevation_follow-marker.html)
|
|
44
44
|
- [layer almostover](https://raruto.github.io/leaflet-elevation/examples/leaflet-elevation_almost-over.html)
|
|
45
|
-
- [linear gradient](https://raruto.github.io/leaflet-elevation/examples/leaflet-
|
|
45
|
+
- [linear gradient](https://raruto.github.io/leaflet-elevation/examples/leaflet-elevation_linear-gradient.html)
|
|
46
46
|
- [slope chart](https://raruto.github.io/leaflet-elevation/examples/leaflet-elevation_slope-chart.html)
|
|
47
47
|
- [speed chart](https://raruto.github.io/leaflet-elevation/examples/leaflet-elevation_speed-chart.html)
|
|
48
48
|
- [walking marker](https://raruto.github.io/leaflet-elevation/examples/leaflet-elevation_dynamic-runner.html)
|
package/package.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@raruto/leaflet-elevation",
|
|
3
|
-
"version": "2.5.
|
|
3
|
+
"version": "2.5.1",
|
|
4
4
|
"description": "A Leaflet plugin that allows to add elevation profiles using d3js",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/leaflet-elevation.min.js",
|
|
7
7
|
"browser": "dist/leaflet-elevation.min.js",
|
|
8
8
|
"module": "src/index.js",
|
|
9
9
|
"scripts": {
|
|
10
|
-
"test": "uvu .
|
|
10
|
+
"test": "uvu . \"(examples|src)[\\\\/].*\\.spec\\.js$\"",
|
|
11
11
|
"build": "rollup -c build/rollup.config.js",
|
|
12
12
|
"watch": "rollup -c build/rollup.config.js --watch",
|
|
13
13
|
"dev": "npm-run-all --print-label --parallel serve watch",
|
package/src/handlers/distance.js
CHANGED
|
@@ -1,46 +1,46 @@
|
|
|
1
|
-
export function Distance() {
|
|
2
|
-
|
|
3
|
-
const _ = L.Control.Elevation.Utils;
|
|
4
|
-
|
|
5
|
-
let opts = this.options;
|
|
6
|
-
let distance = {};
|
|
7
|
-
|
|
8
|
-
opts.distanceFactor = opts.imperial ? this.__mileFactor : (opts.distanceFactor || 1); // 1 km = (1000 m)
|
|
9
|
-
distance.label = opts.imperial ? "mi" : opts.xLabel;
|
|
10
|
-
|
|
11
|
-
return {
|
|
12
|
-
name: 'distance',
|
|
13
|
-
required: true,
|
|
14
|
-
attr: 'dist',
|
|
15
|
-
unit: distance.label,
|
|
16
|
-
decimals: 5,
|
|
17
|
-
pointToAttr: (_, i) => (i > 0 ? this._data[i - 1].dist : 0) + (this._data[i].latlng.distanceTo(this._data[i > 0 ? i - 1 : i].latlng) * opts.distanceFactor) / 1000, // convert back km to meters
|
|
18
|
-
// stats: { total: _.iSum },
|
|
19
|
-
onPointAdded: (distance, i) => this.track_info.distance = distance,
|
|
20
|
-
scale: opts.distance && {
|
|
21
|
-
axis : "x",
|
|
22
|
-
position: "bottom",
|
|
23
|
-
scale : "x", // this._chart._x,
|
|
24
|
-
labelY : 25,
|
|
25
|
-
labelX : () => this._width() + 6,
|
|
26
|
-
ticks : () => _.clamp(this._chart._xTicks() / 2, [4, +Infinity]),
|
|
27
|
-
},
|
|
28
|
-
grid: opts.distance && {
|
|
29
|
-
axis : "x",
|
|
30
|
-
position : "bottom",
|
|
31
|
-
scale : "x" // this._chart._x,
|
|
32
|
-
},
|
|
33
|
-
tooltip: opts.distance && {
|
|
34
|
-
name: 'x',
|
|
35
|
-
chart: (item) => L._("x: ") + _.round(item[opts.xAttr], opts.decimalsX) + " " + distance.label,
|
|
36
|
-
order: 20
|
|
37
|
-
},
|
|
38
|
-
summary: opts.distance && {
|
|
39
|
-
"totlen" : {
|
|
40
|
-
label: "Total Length: ",
|
|
41
|
-
value: (track) => (track.distance || 0).toFixed(2) + ' ' + distance.label,
|
|
42
|
-
order: 10
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
};
|
|
46
|
-
}
|
|
1
|
+
export function Distance() {
|
|
2
|
+
|
|
3
|
+
const _ = L.Control.Elevation.Utils;
|
|
4
|
+
|
|
5
|
+
let opts = this.options;
|
|
6
|
+
let distance = {};
|
|
7
|
+
|
|
8
|
+
opts.distanceFactor = opts.imperial ? this.__mileFactor : (opts.distanceFactor || 1); // 1 km = (1000 m)
|
|
9
|
+
distance.label = opts.imperial ? "mi" : opts.xLabel;
|
|
10
|
+
|
|
11
|
+
return {
|
|
12
|
+
name: 'distance',
|
|
13
|
+
required: true,
|
|
14
|
+
attr: 'dist',
|
|
15
|
+
unit: distance.label,
|
|
16
|
+
decimals: 5,
|
|
17
|
+
pointToAttr: (_, i) => (i > 0 ? this._data[i - 1].dist : 0) + (this._data[i].latlng.distanceTo(this._data[i > 0 ? i - 1 : i].latlng) * opts.distanceFactor) / 1000, // convert back km to meters
|
|
18
|
+
// stats: { total: _.iSum },
|
|
19
|
+
onPointAdded: (distance, i) => this.track_info.distance = distance,
|
|
20
|
+
scale: opts.distance && {
|
|
21
|
+
axis : "x",
|
|
22
|
+
position: "bottom",
|
|
23
|
+
scale : "x", // this._chart._x,
|
|
24
|
+
labelY : 25,
|
|
25
|
+
labelX : () => this._width() + 6,
|
|
26
|
+
ticks : () => _.clamp(this._chart._xTicks() / 2, [4, +Infinity]),
|
|
27
|
+
},
|
|
28
|
+
grid: opts.distance && {
|
|
29
|
+
axis : "x",
|
|
30
|
+
position : "bottom",
|
|
31
|
+
scale : "x" // this._chart._x,
|
|
32
|
+
},
|
|
33
|
+
tooltip: opts.distance && {
|
|
34
|
+
name: 'x',
|
|
35
|
+
chart: (item) => L._("x: ") + _.round(item[opts.xAttr], opts.decimalsX) + " " + distance.label,
|
|
36
|
+
order: 20
|
|
37
|
+
},
|
|
38
|
+
summary: opts.distance && {
|
|
39
|
+
"totlen" : {
|
|
40
|
+
label: "Total Length: ",
|
|
41
|
+
value: (track) => (track.distance || 0).toFixed(2) + ' ' + distance.label,
|
|
42
|
+
order: 10
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
export function Temperature() {
|
|
2
|
+
|
|
3
|
+
const _ = L.Control.Elevation.Utils;
|
|
4
|
+
|
|
5
|
+
let temperature = {};
|
|
6
|
+
let opts = this.options;
|
|
7
|
+
temperature.label = opts.label || L._(opts.imperial ? '°F' : '°C');
|
|
8
|
+
|
|
9
|
+
// Fahrenheit = (Celsius * 9/5) + 32
|
|
10
|
+
opts.temperatureFactor1 = opts.temperatureFactor1 ?? (opts.imperial ? 1.8 : 1);
|
|
11
|
+
opts.temperatureFactor2 = opts.temperatureFactor2 ?? (opts.imperial ? 32 : 0);
|
|
12
|
+
|
|
13
|
+
return {
|
|
14
|
+
name: 'temperature', // <-- Your custom option name (eg. "temperature: true")
|
|
15
|
+
unit: temperature.label,
|
|
16
|
+
meta: 'atemps', // <-- point.meta.atemps
|
|
17
|
+
coordinateProperties: ["atemps"], // List of GPX Extensions ("coordinateProperties") to be handled by "@tmcw/toGeoJSON"
|
|
18
|
+
deltaMax: this.options.temperatureDeltaMax,
|
|
19
|
+
clampRange: this.options.temperatureRange,
|
|
20
|
+
decimals: 2,
|
|
21
|
+
pointToAttr: (point, i) => (point.meta.atemps ?? point.meta.atemps ?? point.prev('temperature')) * opts.temperatureFactor1 + opts.temperatureFactor2,
|
|
22
|
+
stats: { max: _.iMax, min: _.iMin, avg: _.iAvg },
|
|
23
|
+
scale: {
|
|
24
|
+
axis : "y",
|
|
25
|
+
position : "right",
|
|
26
|
+
scale : { min: -1, max: +1 },
|
|
27
|
+
tickPadding: 16,
|
|
28
|
+
labelX : +18,
|
|
29
|
+
labelY : -8,
|
|
30
|
+
},
|
|
31
|
+
path: {
|
|
32
|
+
label : temperature.label,
|
|
33
|
+
yAttr : 'temperature',
|
|
34
|
+
scaleX : 'distance',
|
|
35
|
+
scaleY : 'temperature',
|
|
36
|
+
color : 'transparent',
|
|
37
|
+
strokeColor : '#000',
|
|
38
|
+
strokeOpacity: "0.85",
|
|
39
|
+
// fillOpacity : "0.1",
|
|
40
|
+
},
|
|
41
|
+
tooltip: {
|
|
42
|
+
name: 'temperature',
|
|
43
|
+
chart: (item) => L._("Temp: ") + Math.round(item.temperature).toLocaleString() + " " + temperature.label,
|
|
44
|
+
marker: (item) => Math.round(item.temperature).toLocaleString() + " " + temperature.label,
|
|
45
|
+
order: 1
|
|
46
|
+
},
|
|
47
|
+
summary: {
|
|
48
|
+
"mintemp": {
|
|
49
|
+
label: "Min Temp: ",
|
|
50
|
+
value: (track, unit) => Math.round(track.temperature_min || 0) + ' ' + unit,
|
|
51
|
+
},
|
|
52
|
+
"maxtemp": {
|
|
53
|
+
label: "Max Temp: ",
|
|
54
|
+
value: (track, unit) => Math.round(track.temperature_max || 0) + ' ' + unit,
|
|
55
|
+
},
|
|
56
|
+
"avgtemp": {
|
|
57
|
+
label: "Avg Temp: ",
|
|
58
|
+
value: (track, unit) => Math.round(track.temperature_avg || 0) + ' ' + unit,
|
|
59
|
+
},
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
}
|