Skip to content

Commit 229d734

Browse files
committed
Context: stop map snapping on refresh
Changes: - Only auto-fit to Traccar route on first-run when no saved view exists and user hasn't moved map - Persist route-fit flag on the map element to avoid snapping across HA re-renders - Remove redundant PMTiles label under map Verification: - node -c homeassistant/www/roamcore/roamcore-pages.js Rollback: - Revert this commit
1 parent 03f6a0c commit 229d734

1 file changed

Lines changed: 12 additions & 4 deletions

File tree

homeassistant/www/roamcore/roamcore-pages.js

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1490,9 +1490,17 @@ class RoamcoreBasePage extends HTMLElement {
14901490
});
14911491
}
14921492

1493-
// Auto-fit to the route once, so the demo immediately looks like a trip.
1493+
// Auto-fit to the route once (first-run only).
1494+
// IMPORTANT: never override a user-restored view.
1495+
// - If we loaded a saved view from localStorage, keep it.
1496+
// - If the user already panned/zoomed, keep it.
1497+
// - Persist the "did fit" flag on the *element*, not the page instance,
1498+
// so HA re-renders don't cause repeated snapping.
14941499
try {
1495-
if (!this._rcRouteFitDone) {
1500+
const alreadyFit = !!el._rcRouteFitDone;
1501+
const userMoved = !!el._rcUserMoved;
1502+
const hasSaved = !!saved;
1503+
if (!alreadyFit && !userMoved && !hasSaved) {
14961504
const bounds = new maplibregl.LngLatBounds();
14971505
const addCoord = (c) => { if (c && c.length >= 2) bounds.extend([c[0], c[1]]); };
14981506
if (gj.geometry.type === 'LineString') {
@@ -1502,7 +1510,7 @@ class RoamcoreBasePage extends HTMLElement {
15021510
}
15031511
if (!bounds.isEmpty()) {
15041512
m.fitBounds(bounds, { padding: 40, duration: 0, maxZoom: 8 });
1505-
this._rcRouteFitDone = true;
1513+
el._rcRouteFitDone = true;
15061514
}
15071515
}
15081516
} catch (e) {}
@@ -2070,7 +2078,7 @@ class RoamcoreMapPage extends RoamcoreBasePage {
20702078
<div style="color: var(--rc-good); font-weight:900">⌖</div>
20712079
<div style="font-weight:800; overflow:hidden; text-overflow:ellipsis; white-space:nowrap;">${(loc && loc!=='unknown' && loc!=='unavailable') ? loc : '—'}</div>
20722080
</div>
2073-
<div class="rc-label" style="margin-top: 6px;">RoamCore map (PMTiles vector) with route overlay.</div>
2081+
20742082
<div style="margin-top: 10px; display:flex; gap:10px; flex-wrap:wrap;">
20752083
<a class="rc-btn" href="${this._traccarEmbedUrl()}" target="_blank" rel="noreferrer">Open Traccar (fullscreen)</a>
20762084
</div>

0 commit comments

Comments
 (0)