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.
|
private suspend inline fun MapView.newComposition( |
|
parent: CompositionContext, |
|
noinline content: @Composable () -> Unit |
|
): Composition { |
|
val map = awaitMap() |
|
return Composition( |
|
MapApplier(map, this), parent |
|
).apply { |
|
setContent(content) |
|
} |
|
} |
|
LaunchedEffect(Unit) { |
|
disposingComposition { |
|
mapView.newComposition(parentComposition) { |
|
MapUpdater( |
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
MapViewwould start being rendered, so the initial camera position should be set pronto.Does this make sense? Looking for feedback.
android-maps-compose/maps-compose/src/main/java/com/google/maps/android/compose/GoogleMap.kt
Lines 158 to 168 in 4b7967d
android-maps-compose/maps-compose/src/main/java/com/google/maps/android/compose/GoogleMap.kt
Lines 126 to 129 in 4b7967d