Hello all, I am struggling with maps compose and a...
# compose
b
Hello all, I am struggling with maps compose and a recompose causing a TileOverlay to flicker. Wondering if someone could provide some insight. Code in reply.
I am waiting for the map to load before I change the camera location via an animation. However when I do that a recompose is happening, assuming this is what is causing the TileOverlay layer to flicker at the start.
Copy code
@Composable
private fun Map() {
  var isMapLoaded by remember { mutableStateOf(false) }

  GoogleMap(
    onMapLoaded = { isMapLoaded = true }  // This will cause recompose
  ) {
    if (isMapLoaded) {
      // Need to wait for map loaded to preform map camera location animation.
    }

    // Assume flicker here is caused by recompose and reload of TileOverlay
    TileOverlay(tileProvider = MyTileProvider())
  }
}
I was under the assumption that the GoogleMap composable would keep track of the TileOverlay and not reload it on recompose. Is that assumption wrong? Something else I am doing wrong? I can put the TileOverlay inside the isMapLoaded check to fix/workaround the issue. However at that point should I put everything map related inside that if statement?
@Colton Idle, @Chris Arriola any thoughts you can offer?
c
@Billy Newman looks like you are creating a new instance of MyTileProvider() each time, if you want to use the same instance across recomposition you need to
remember
the
MyTileProvider
. sorry for the delay here.
b
Awesome and it goes without saying, no apologies necessary. I appreciate your time whenever you can give it!