feat: add per-trip use_gpx and autoconnect toggles
Adds two configurable toggles to the trip blueprint (Admin2 Trip tab): - use_gpx: show/hide GPX tracks on all maps (default: enabled) - autoconnect: draw connector lines between markers (default: enabled) When use_gpx is off, GPX files are not fetched or rendered on any map (home, map, trip, dailies). The stats panel in trip.html.twig still reads GPX_URLS directly and is unaffected. When autoconnect is off, buildJourneySegments suppresses all auto-connectors; only entries with force_connect:true still draw a line — making force_connect behaviour independent of both settings. Also refactors the inline Promise.all in trip.html.twig to use the shared renderGpxJourney utility (reducing duplication). Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Vgmzx8VTTTmCskSpQtsLTr
This commit is contained in:
@@ -223,8 +223,13 @@
|
||||
* - GPX present, pair NOT covered by any single file → connector drawn
|
||||
* - force_connect on arriving entry → always draw connector
|
||||
*/
|
||||
function buildJourneySegments(entries, allTrackpoints, thresholdKm) {
|
||||
thresholdKm = thresholdKm || 10;
|
||||
/*
|
||||
* opts.autoconnect (bool, default true): when false, only entries with
|
||||
* force_connect:true are connected — all other pairs are left unconnected.
|
||||
*/
|
||||
function buildJourneySegments(entries, allTrackpoints, thresholdKm, opts) {
|
||||
thresholdKm = thresholdKm || 10;
|
||||
var autoconnect = !opts || opts.autoconnect !== false;
|
||||
var hasGpx = allTrackpoints && allTrackpoints.length > 0;
|
||||
var segments = [];
|
||||
var current = [];
|
||||
@@ -241,7 +246,11 @@
|
||||
var prev = entries[i - 1];
|
||||
var connect;
|
||||
|
||||
if (!hasGpx || e.force_connect) {
|
||||
if (e.force_connect) {
|
||||
connect = true;
|
||||
} else if (!autoconnect) {
|
||||
connect = false;
|
||||
} else if (!hasGpx) {
|
||||
connect = true;
|
||||
} else {
|
||||
var pLat = parseFloat(prev.lat);
|
||||
@@ -295,7 +304,7 @@
|
||||
* When gpxUrls is empty, Promise.all resolves immediately → no GPX layers,
|
||||
* buildJourneySegments draws a full connector line between all entries.
|
||||
*/
|
||||
function renderGpxJourney(map, gpxUrls, entries, gpxSourcePrefix, journeySourceId) {
|
||||
function renderGpxJourney(map, gpxUrls, entries, gpxSourcePrefix, journeySourceId, opts) {
|
||||
Promise.all(gpxUrls.map(function (url, idx) {
|
||||
return fetch(url)
|
||||
.then(function (r) { return r.text(); })
|
||||
@@ -314,7 +323,7 @@
|
||||
.catch(function (err) { console.warn('GPX load failed:', url, err); return []; });
|
||||
})).then(function (allTrackpoints) {
|
||||
var valid = allTrackpoints.filter(function (tp) { return tp.length > 0; });
|
||||
var segments = buildJourneySegments(entries, valid, 10);
|
||||
var segments = buildJourneySegments(entries, valid, 10, opts);
|
||||
addJourneySegments(map, segments, journeySourceId);
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user