Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Restore zoom + camera position state when returning to map #472

Merged
merged 1 commit into from
Feb 1, 2025

Conversation

thgoebel
Copy link
Contributor

Previously, when switching between tabs and returning to the map, the state would be reset to the latestReportPosition.
(Personally, especially the zoom being reset annoys me, since when mapping in a city I zoom in much more than the default of 10. Even the 12 that I now changed the default to is still quite far out for city/street-level.)

Instead, restore it to the last position and zoom that the user navigated to.

Also move this logic from update() to factory(), since it only needs to run once.

@thgoebel thgoebel force-pushed the keep-state branch 2 times, most recently from 24f3266 to e938b2d Compare February 1, 2025 07:56
Comment on lines 197 to 213
val target = if (mapViewModel.mapCenter.value.isOrigin()) {
latestReportPosition.value
} else {
mapViewModel.mapCenter.value
}
map.cameraPosition = CameraPosition.Builder()
.target(target?.asMapLibreLatLng())
.zoom(mapViewModel.zoom.value)
.build()
Copy link
Owner

Choose a reason for hiding this comment

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

This has to be done in the update() function, because the latest report position is loaded asynchronously and it might not be available when the view is initialized

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In my testing, this was never a problem, the latestReportPosition was always available. But sure, I’ll change it back to update().

Copy link
Owner

@mjaakko mjaakko left a comment

Choose a reason for hiding this comment

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

Thanks!

For the default map zoom level, I'm not sure what would be a good value. It depends a lot on your use case. For example, personally I usually use the map to get an overview of the areas where I have not yet collected data and in that case a good default would be to zoom to the city level. But I'll test how this looks and maybe change it depending on how it feels

@thgoebel
Copy link
Contributor Author

thgoebel commented Feb 1, 2025

This is why I only increased it to 12. There, it still comfortably fits 100-500K person cities (e.g. Zürich) on my screen, while also showing just a bit more street details. Of course, it will also vary by screen size and resolution. It’s not a radical change, but I find it a bit easier.

Previously, when switching between tabs and returning to the map, the state
would be reset to the latestReportPosition.
Instead, restore it to the last position and zoom that the user navigated to.
@mjaakko mjaakko merged commit adf75e1 into mjaakko:master Feb 1, 2025
6 checks passed
@thgoebel thgoebel deleted the keep-state branch February 1, 2025 15:43
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.

2 participants