From 91bbe1a67fdfecb33e0d863213b8c504bcb2ad36 Mon Sep 17 00:00:00 2001 From: efiten Date: Wed, 10 Jun 2026 16:37:22 +0200 Subject: [PATCH] fix(app): live GPS marker/follow updates continuously, not only on RX The map's position marker only moved when a packet arrived, so it appeared to hang and jump. GPS fixes (watchPosition) now feed the map directly via setPosition; hexes are still added only on a real RX. --- package.json | 2 +- src/app.js | 2 +- src/gps.js | 9 +++++++-- src/localmap.js | 18 +++++++++++++----- 4 files changed, 22 insertions(+), 9 deletions(-) diff --git a/package.json b/package.json index a245241..177b4e9 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "corescope-rx", - "version": "0.5.0", + "version": "0.5.1", "private": true, "type": "module", "description": "Mobile RX coverage capture for CoreScope: BLE companion → MQTT (GPS + SNR/RSSI + multibyte)", diff --git a/src/app.js b/src/app.js index 9bc61a3..a0f0ef5 100644 --- a/src/app.js +++ b/src/app.js @@ -174,7 +174,7 @@ async function connectAll() { els('companionInfo').textContent = state.companionPubkey.slice(0, 20) + '…'; dbg('SELF_INFO → ' + (info.name || '(unnamed)') + ' ' + state.companionPubkey); - state.gps.start(); + state.gps.start((fix) => { if (state.localMap) state.localMap.setPosition(fix.lat, fix.lon); }); const s3 = step('③ Connecting to ON8AR CoreScope…', 'pending'); if (MQTT_CFG.url) { diff --git a/src/gps.js b/src/gps.js index 14959e5..b005daa 100644 --- a/src/gps.js +++ b/src/gps.js @@ -3,10 +3,15 @@ export class Gps { constructor() { this._last = null; this._watchId = null; } - start() { + // start(onFix): begins watching; onFix (optional) fires on every position + // update so the UI can track GPS continuously, independent of RX packets. + start(onFix) { if (!navigator.geolocation) throw new Error('geolocation unavailable'); this._watchId = navigator.geolocation.watchPosition( - (p) => { this._last = { lat: p.coords.latitude, lon: p.coords.longitude, acc_m: p.coords.accuracy }; }, + (p) => { + this._last = { lat: p.coords.latitude, lon: p.coords.longitude, acc_m: p.coords.accuracy }; + if (onFix) onFix(this._last); + }, () => {}, { enableHighAccuracy: true, maximumAge: 5000, timeout: 15000 } ); diff --git a/src/localmap.js b/src/localmap.js index 6d5321e..e696f40 100644 --- a/src/localmap.js +++ b/src/localmap.js @@ -71,15 +71,23 @@ export function createLocalMap(containerId) { if (nr !== res) { res = nr; rebuild(); } }); + // setPos moves the "you are here" marker and (when following) keeps it centred. + // Called continuously from GPS — independent of RX — so the position is live. + function setPos(lat, lon) { + if (lat == null || lon == null) return; + if (!me) me = L.circleMarker([lat, lon], { radius: 5, color: '#fff', weight: 2, fillColor: '#3b82f6', fillOpacity: 1 }).addTo(map); + else me.setLatLng([lat, lon]); + if (!centered) { centered = true; map.setView([lat, lon], 15); } // initial zoom + else if (follow) map.panTo([lat, lon]); // follow GPS, keep current zoom + } + return { - addPoint(lat, lon, snr) { + setPosition(lat, lon) { setPos(lat, lon); }, // live GPS, no hex + addPoint(lat, lon, snr) { // an RX: add a hex + sync position points.push({ lat, lon, snr }); if (points.length > POINT_CAP) points.shift(); upsert(lat, lon, snr); - if (!me) me = L.circleMarker([lat, lon], { radius: 5, color: '#fff', weight: 2, fillColor: '#3b82f6', fillOpacity: 1 }).addTo(map); - else me.setLatLng([lat, lon]); - if (!centered) { centered = true; map.setView([lat, lon], 15); } // initial zoom - else if (follow) map.panTo([lat, lon]); // follow GPS, keep current zoom + setPos(lat, lon); }, invalidate() { setTimeout(() => { try { map.invalidateSize(); } catch (e) {} }, 150); }, destroy() { try { map.remove(); } catch (e) {} },