summaryrefslogtreecommitdiff
path: root/assets/static/vendor/leaflet-elevation/src/handlers/distance.js
diff options
context:
space:
mode:
authorDennis Fink2026-07-23 00:18:21 +0200
committerDennis Fink2026-07-23 00:18:21 +0200
commit1fe1d13c600b7dfe421b3b99b833b7d5d1232724 (patch)
tree2e8636160cc1719c907be56f5ef8cbc7e0f10a53 /assets/static/vendor/leaflet-elevation/src/handlers/distance.js
parentca77de06be474dfd712402c327dc436864d233a3 (diff)
downloaddennisfink.me-1fe1d13c600b7dfe421b3b99b833b7d5d1232724.tar.gz
dennisfink.me-1fe1d13c600b7dfe421b3b99b833b7d5d1232724.zip
Add GPX trail maps to blog posts
This adds a trail flow block so posts can include attached GPX files as interactive maps with route display, elevation charts, activity summaries, and start/finish markers. The trail assets are loaded only when needed, keeping the shared templates clean while vendoring the Leaflet dependencies required for offline, self-hosted map rendering.
Diffstat (limited to '')
-rw-r--r--assets/static/vendor/leaflet-elevation/src/handlers/distance.js46
1 files changed, 46 insertions, 0 deletions
diff --git a/assets/static/vendor/leaflet-elevation/src/handlers/distance.js b/assets/static/vendor/leaflet-elevation/src/handlers/distance.js
new file mode 100644
index 0000000..fa6fa1d
--- /dev/null
+++ b/assets/static/vendor/leaflet-elevation/src/handlers/distance.js
@@ -0,0 +1,46 @@
+export function Distance() {
+
+ const _ = L.Control.Elevation.Utils;
+
+ let opts = this.options;
+ let distance = {};
+
+ opts.distanceFactor = opts.imperial ? this.__mileFactor : (opts.distanceFactor || 1); // 1 km = (1000 m)
+ distance.label = opts.imperial ? "mi" : opts.xLabel;
+
+ return {
+ name: 'distance',
+ required: true,
+ attr: 'dist',
+ unit: distance.label,
+ decimals: 5,
+ 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
+ // stats: { total: _.iSum },
+ onPointAdded: (distance, i) => this.track_info.distance = distance,
+ scale: opts.distance && {
+ axis : "x",
+ position: "bottom",
+ scale : "x", // this._chart._x,
+ labelY : 25,
+ labelX : () => this._width() + 6,
+ ticks : () => _.clamp(this._chart._xTicks() / 2, [4, +Infinity]),
+ },
+ grid: opts.distance && {
+ axis : "x",
+ position : "bottom",
+ scale : "x" // this._chart._x,
+ },
+ tooltip: opts.distance && {
+ name: 'x',
+ chart: (item) => L._("x: ") + _.round(item[opts.xAttr], opts.decimalsX) + " " + distance.label,
+ order: 20
+ },
+ summary: opts.distance && {
+ "totlen" : {
+ label: "Total Length: ",
+ value: (track) => (track.distance || 0).toFixed(2) + ' ' + distance.label,
+ order: 10
+ }
+ }
+ };
+}