pwaLUPMIS2/src/geotracker-lupmis.js
ekke cfaceb3487 GPS trail recording, SSO auth, account menu, and mobile/UI refinements
Major:
- GPS trail recording: reusable, dependency-free engine in src/geotracker/
  (GeoTracker + geo-utils) with pluggable storage/sync adapters; LUPMIS
  wiring in src/geotracker-lupmis.js. Expandable My Location control
  (Locate Me + Record Trail), live navbar GPS readout, on-map trail/position
  rendering, gps_trails/gps_trail_points SQLocal tables, and store-and-forward
  sync via pushGpsTrail() -> save_gps_trail.php (server side documented, not
  yet built).
- SSO authentication: public/index.php entry point validates the LUSPA SSO
  cookie and injects window.LUPMIS_SESSION; remotedb district_id is now a
  session-resolved getter. Adds public/.htaccess (DirectoryIndex).
- Account menu offcanvas (navbar burger) with sign-in/out states.

UI / fixes:
- LayerSwitcher modernisation; base-map "None" option in picker + settings.
- Mobile drawing toolbar wraps to two rows below 576px and shows only in
  Draw mode; second row right-aligned and clears the Select option bar.
- Safari bottom-dock clipping fixed (app-container 100dvh -> 100svh).
- Rename public/icons -> app-icons to dodge Apache's default /icons/ alias.
- Service Worker bumped to v8 (network-first HTML, per-provider tile clear).

Docs: reusable-mapping and OSM-3D-buildings concept notes; ignore Office
lock files (~$*). Rebuilt dist/.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-28 16:08:37 +02:00

69 lines
2.3 KiB
JavaScript

/**
* geotracker-lupmis.js — LUPMIS2 integration layer for the reusable GeoTracker.
*
* This is the ONLY place that couples the generic src/geotracker/ engine to
* LUPMIS specifics (SQLocal storage, the PHP sync endpoint, district id,
* online checks). To reuse GeoTracker in another app, copy src/geotracker/ and
* write a file like this one with that app's storage + sync adapters.
*
* @module geotracker-lupmis
*/
import { GeoTracker } from './geotracker/GeoTracker.js';
import {
createGpsTrail,
addGpsTrailPoint,
finishGpsTrail,
getUnsyncedGpsTrails,
getGpsTrailPoints,
markGpsTrailSynced,
} from './database.js';
import { pushGpsTrail } from './remotedb.js';
import { isOnline } from './pwa.js';
import { getSession } from './remotedb.js';
/**
* Storage adapter — maps the GeoTracker contract onto the SQLocal helpers in
* database.js. The district id is stamped onto each trail at creation time.
*/
const sqlocalStorage = {
async createTrail(meta) {
const districtId = meta.districtId
?? getSession()?.district_id
?? null;
return createGpsTrail({ ...meta, districtId: districtId != null ? String(districtId) : null });
},
addPoint: (trailId, point) => addGpsTrailPoint(trailId, point),
finishTrail: (trailId, summary) => finishGpsTrail(trailId, summary),
getUnsyncedTrails: () => getUnsyncedGpsTrails(),
getTrailPoints: (trailId) => getGpsTrailPoints(trailId),
markTrailSynced: (trailId, remote) => markGpsTrailSynced(trailId, remote),
};
/**
* Sync adapter — store-and-forward upload via the PHP endpoint. `isOnline()`
* lets the tracker skip pushes while offline (it retries later).
*/
const remoteSync = {
pushTrail: (trail, points) => pushGpsTrail(trail, points),
isOnline: () => isOnline(),
};
/**
* The configured, app-wide tracker instance. Tunables chosen for field
* walking/driving: a point every ~5 m, throttled to ≥1 s, with a 20 s
* heartbeat so stationary pauses still leave a breadcrumb, dropping fixes
* worse than 50 m accuracy.
*/
export const geoTracker = new GeoTracker({
storage: sqlocalStorage,
sync: remoteSync,
minDistanceM: 5,
minIntervalMs: 1000,
heartbeatMs: 20000,
maxAccuracyM: 50,
enableHighAccuracy: true,
});
export default geoTracker;