Skip to content

Commit

Permalink
docs: added custom zoom controls
Browse files Browse the repository at this point in the history
  • Loading branch information
kikoso committed Nov 13, 2023
1 parent 52d0342 commit 0684caa
Showing 1 changed file with 41 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ import androidx.compose.animation.EnterTransition
import androidx.compose.animation.fadeOut
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.wrapContentSize
import androidx.compose.material.Button
Expand All @@ -35,9 +37,12 @@ import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
import com.google.android.gms.maps.CameraUpdateFactory
import kotlinx.coroutines.launch


class CustomControlsActivity : ComponentActivity() {
Expand All @@ -47,9 +52,17 @@ class CustomControlsActivity : ComponentActivity() {

setContent {
var isMapLoaded by remember { mutableStateOf(false) }
val coroutineScope = rememberCoroutineScope()
// This needs to be manually deactivated to avoid having a custom and the native
// location button
val uiSettings by remember { mutableStateOf(MapUiSettings(myLocationButtonEnabled = false)) }
val uiSettings by remember {
mutableStateOf(
MapUiSettings(
myLocationButtonEnabled = false,
zoomGesturesEnabled = false
)
)
}
// Observing and controlling the camera's state can be done with a CameraPositionState
val cameraPositionState = rememberCameraPositionState {
position = defaultCameraPosition
Expand All @@ -64,15 +77,6 @@ class CustomControlsActivity : ComponentActivity() {
},
uiSettings = uiSettings,
)
MapButton(
"This is a custom location button",
onClick = {
Toast.makeText(
this@CustomControlsActivity,
"Click on my location",
Toast.LENGTH_SHORT
).show()
})

if (!isMapLoaded) {
AnimatedVisibility(
Expand All @@ -89,6 +93,33 @@ class CustomControlsActivity : ComponentActivity() {
)
}
}
Column(
modifier = Modifier.fillMaxWidth()
) {
MapButton(
"This is a custom location button",
onClick = {
Toast.makeText(
this@CustomControlsActivity,
"Click on my location",
Toast.LENGTH_SHORT
).show()
})
MapButton(
"+",
onClick = {
coroutineScope.launch {
cameraPositionState.animate(CameraUpdateFactory.zoomIn())
}
})
MapButton(
"-",
onClick = {
coroutineScope.launch {
cameraPositionState.animate(CameraUpdateFactory.zoomOut())
}
})
}
}
}
}
Expand Down

0 comments on commit 0684caa

Please sign in to comment.