googlemaps / googlemaps/android-maps-compose
Map initialization with desired configuration is delayed
- Dominant language
- Kotlin
- Stars
- 1.3k
- Forks
- 181
- Avg merge
- 2d 23h
- Merged PRs (30d)
- 18
Description
Setting an initial camera position for the GoogleMap is commonly done by passing an appropriately initialized CameraPositionState parameter to the GoogleMap() Composable.
While reviewing the android-maps-compose code (4.3.0) I noticed that the GoogleMap camera is moved to its initial requested position (via CameraPositionState) only during the (sub-) composition apply phase. I believe this means that the entire initial sub-composition (short of applying) has to complete first. I think this could mean a significant delay in map position initialization, in particular if the sub-composition is fairly sizable.
Delaying map position initialization implies that loading tiles for the desired position is delayed. It would also mean additional visual artifacts, such as missing tiles and visually changing the map center from (0.0, 0.0) to the desired camera location.
From looking at the code I think it would be fairly easy and trouble-free to preempt the delay. The desired position is readily available before initializing the subcomposition and can be set right after `awaitMap()` has returned.
In terms of correctness, the parent composition would have completed at this point already, so the information from CameraPositionState can be considered valid/committed. I would expect that at this point the `MapView` would start being rendered, so the initial camera position should be set pronto.
Does this make sense? Looking for feedback.
https://github.com/googlemaps/android-maps-compose/blob/4b7967d15f8add4589e7d02cf8bf71f1c594f59d/maps-compose/src/main/java/com/google/maps/android/compose/GoogleMap.kt#L158-L168
https://github.com/googlemaps/android-maps-compose/blob/4b7967d15f8add4589e7d02cf8bf71f1c594f59d/maps-compose/src/main/java/com/google/maps/android/compose/GoogleMap.kt#L126-L129
Contributor guide
Assessment
This issue has not been assessed yet.