Skip to content

Make CameraPosition serializable for view-model saved state - #1390

Open
sargunv wants to merge 2 commits into
mainfrom
cursor/camera-position-serializable-df8c
Open

Make CameraPosition serializable for view-model saved state#1390
sargunv wants to merge 2 commits into
mainfrom
cursor/camera-position-serializable-df8c

Conversation

@sargunv

@sargunv sargunv commented Sep 10, 2026

Copy link
Copy Markdown
Collaborator

Resolve #1389

Description

CameraPosition is now @Serializable so a view model that owns MapState can persist the camera with kotlinx.serialization.

rememberMapState still saves the camera through its private List<Double> saver. Apps that create the state with MapRuntime.createMapState no longer need to copy that encoding or write a custom serializer.

The generated serializer includes Position.altitude when the target has one. The composition saver still stores only longitude and latitude.

Validation

Ran :lib:maplibre-compose:jvmTest --tests org.maplibre.compose.camera.CameraPositionTest on Linux. Both tests passed:

  • roundTripsCameraThroughJson encodes and decodes bearing, target (including altitude), tilt, and zoom
  • restoresOmittedFieldsToConstructorDefaults decodes {} to CameraPosition()

Not run: JS and Native suites. The serializer is generated shared Kotlin and uses Spatial-K's existing Position serializer.

AI assistance

Cursor Grok 4.6 (Cloud Agent) drafted the change and tests.

Open in Web Open in Cursor 

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>
@sargunv
sargunv marked this pull request as ready for review September 10, 2026 09:20
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 10, 2026

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review Completed 2026-09-10T09:26:28.536514Z a82cb37 Draft marked ready
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

Comment thread docs/src/content/docs/camera.mdx Outdated
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>

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment on lines +12 to +13
* [org.maplibre.compose.map.rememberMapState] already saves the camera when composition owns the
* state.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Make CameraPosition serializable for view-model saved state

2 participants