Make CameraPosition serializable for view-model saved state - #1390
Make CameraPosition serializable for view-model saved state#1390sargunv wants to merge 2 commits into
Conversation
Annotate CameraPosition with kotlinx.serialization so apps that own MapState outside rememberMapState can persist the camera without a custom serializer. Co-authored-by: Sargun Vohra <sargunv@users.noreply.github.com>
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
Keep the serializer. The annotation is enough without restating it in KDoc or the camera guide. Co-authored-by: Sargun Vohra <sargunv@users.noreply.github.com>
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: a82cb3741e
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| * [org.maplibre.compose.map.rememberMapState] already saves the camera when composition owns the | ||
| * state. |
There was a problem hiding this comment.
Preserve or disclose altitude during composition restoration
When target.altitude is non-null, this statement overpromises restoration: mapStateSaver in MapRuntime.kt:1871-1886 stores only bearing, longitude, latitude, tilt, and zoom, then reconstructs Position without altitude. A save/restore cycle through rememberMapState therefore changes the CameraPosition, unlike the newly tested serializer; either retain altitude in the saver or qualify this KDoc and the matching camera guide.
AGENTS.md reference: AGENTS.md:L70-L71
Useful? React with 👍 / 👎.
Resolve #1389
Description
CameraPositionis now@Serializableso a view model that ownsMapStatecan persist the camera with kotlinx.serialization.rememberMapStatestill saves the camera through its privateList<Double>saver. Apps that create the state withMapRuntime.createMapStateno longer need to copy that encoding or write a custom serializer.The generated serializer includes
Position.altitudewhen the target has one. The composition saver still stores only longitude and latitude.Validation
Ran
:lib:maplibre-compose:jvmTest --tests org.maplibre.compose.camera.CameraPositionTeston Linux. Both tests passed:roundTripsCameraThroughJsonencodes and decodes bearing, target (including altitude), tilt, and zoomrestoresOmittedFieldsToConstructorDefaultsdecodes{}toCameraPosition()Not run: JS and Native suites. The serializer is generated shared Kotlin and uses Spatial-K's existing
Positionserializer.AI assistance
Cursor Grok 4.6 (Cloud Agent) drafted the change and tests.