fix(map): restore last-viewed region on launch (fixes (0,0) cold-open)#2115
fix(map): restore last-viewed region on launch (fixes (0,0) cold-open)#2115bruschill wants to merge 1 commit into
Conversation
The Mesh Map's one-shot frameInitialRegionIfNeeded() centers on phone GPS -> connected device -> node centroid. A location-denied user with no connected device and no positioned nodes hits none of the three, the frame never fires, and MKMapView shows its default world view centered near (0,0) -- the "South Atlantic / Null Island" cold-open -- on every launch. Persist the last-viewed MKCoordinateRegion via @AppStorage and restore it as the first choice in the one-shot, so anyone who has ever moved the map reopens where they left it, independent of GPS / connected device / node data. No new camera machinery, per the path forward in meshtastic#2018. - Save on pan/zoom settle, guarding against the degenerate (0,0)/near-global default MapKit reports before the first real frame so the bug is never persisted (whole-world span guard + a Null-Island center guard). - Round-trip validation (finite, in-range, positive span) on restore. - Document the behavior in docs/user/map.md and regenerate the bundled docs.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (5)
📝 WalkthroughWalkthroughThe map now saves a validated camera region after movement and restores it on launch. Documentation describes this behavior and the fresh-install framing fallback order, with updated search metadata. ChangesMap camera persistence
Estimated code review effort: 2 (Simple) | ~10 minutes Possibly related PRs
Suggested reviewers: Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
What & why
Follow-up to the "path forward" from @garthvh's review of #2018.
The Mesh Map's one-shot
frameInitialRegionIfNeeded()centers on phone GPS → connected device position → node centroid, guarded bydidInitialFrame. A location-denied user with no connected device and no positioned nodes hits none of the three, so the frame never fires andMKMapViewfalls back to its default world view centered near (0,0) — the "South Atlantic / Null Island" cold-open — on every launch, since nothing was ever persisted.Per the agreed path forward, this is the region-persistence-only fix — no pending-camera-command plumbing, no follow-the-user floor, no new camera machinery:
MKCoordinateRegionvia@AppStorage(fourDoubles, sinceMKCoordinateRegionisn'tCodable).frameInitialRegionIfNeeded(), before the GPS/device/centroid path. Anyone who has ever moved the map reopens exactly where they left it, independent of GPS/device/node data. It consumes the one-shot, so the user still owns the camera immediately after.Not persisting the bug
Saving happens on pan/zoom settle (the existing
regionRefreshKeyonChange), guarded so the degenerate default is never written back:< 90°latitude and< 180°longitude; you can't fit the entire world under half-extent on both axes, so MapKit's settled default is always rejected.Behavior
Analogous to the already-documented "Filters are remembered between launches" (nodes.md).
Docs
Documented the behavior in
docs/user/map.mdand regenerated the bundled docs (scripts/build-docs.sh); generated HTML/JSON not hand-edited.Testing
MeshMapMK.swift; SwiftLint clean for the new code (only the pre-existingtype_body_lengthon the struct).ClusterMapViewcamera coordinator: the one-shotcameraCommandid-dedup +isApplyingExternalRegionfeedback guard mean restore correctly consumes the one-shot.Note: the persist/restore validation currently lives as
privatemethods on the view; a small extraction into a testable helper (to pin the accept/reject boundaries inMeshtasticTests) is a reasonable follow-up if desired.Summary by CodeRabbit
New Features
Documentation