Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,12 @@ import androidx.compose.ui.test.junit4.createAndroidComposeRule
import androidx.compose.ui.test.onNodeWithTag
import androidx.compose.ui.test.onNodeWithText
import androidx.compose.ui.test.performClick
import androidx.test.annotation.UiThreadTest
import com.google.android.gms.maps.model.CameraPosition
import com.google.android.gms.maps.model.LatLng
import org.junit.Assert.assertEquals
import org.junit.Assert.assertFalse
import org.junit.Assert.assertNotNull
import org.junit.Assert.assertTrue
import org.junit.Before
import org.junit.Rule
Expand Down Expand Up @@ -86,7 +88,7 @@ class GoogleMapViewTests {
composeTestRule.waitUntil(1000) {
cameraPositionState.isMoving
}
composeTestRule.waitUntil(1000) {
composeTestRule.waitUntil(3000) {
!cameraPositionState.isMoving
}
assertFalse(cameraPositionState.isMoving)
Expand Down Expand Up @@ -150,7 +152,7 @@ class GoogleMapViewTests {
composeTestRule.waitUntil(1000) {
cameraPositionState.isMoving
}
composeTestRule.waitUntil(1000) {
composeTestRule.waitUntil(3000) {
!cameraPositionState.isMoving
}
assertEquals(
Expand All @@ -161,7 +163,32 @@ class GoogleMapViewTests {
}
}

private fun zoom(shouldAnimate: Boolean, zoomIn: Boolean, assertionBlock: () -> Unit) {
@Test
@UiThreadTest
fun testLatLngInVisibleRegion() {
val projection = cameraPositionState.projection
assertNotNull(projection)
assertTrue(
projection!!.visibleRegion.latLngBounds.contains(startingPosition)
)
}

@Test
@UiThreadTest
fun testLatLngNotInVisibleRegion() {
val projection = cameraPositionState.projection
assertNotNull(projection)
val latLng = LatLng(23.4, 25.6)
assertFalse(
projection!!.visibleRegion.latLngBounds.contains(latLng)
)
}

private fun zoom(
shouldAnimate: Boolean,
zoomIn: Boolean,
assertionBlock: () -> Unit
) {
if (!shouldAnimate) {
composeTestRule.onNodeWithTag("cameraAnimations")
.assertIsDisplayed()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ import androidx.compose.ui.graphics.Color
import androidx.compose.ui.platform.testTag
import androidx.compose.ui.unit.dp
import com.google.android.gms.maps.CameraUpdateFactory
import com.google.android.gms.maps.GoogleMapOptions
import com.google.android.gms.maps.model.BitmapDescriptorFactory
import com.google.android.gms.maps.model.CameraPosition
import com.google.android.gms.maps.model.LatLng
Expand All @@ -60,6 +59,7 @@ private const val TAG = "MapSampleActivity"

val singapore = LatLng(1.35, 103.87)
val singapore2 = LatLng(1.40, 103.77)
val singapore3 = LatLng(1.45, 103.77)

class MapSampleActivity : ComponentActivity() {

Expand Down Expand Up @@ -126,6 +126,9 @@ fun GoogleMapView(
// Drawing on the map is accomplished with a child-based API
val markerClick: (Marker) -> Boolean = {
Log.d(TAG, "${it.title} was clicked")
cameraPositionState.projection?.let { projection ->
Log.d(TAG, "The current projection is: $projection")
}
false
}
MarkerInfoWindowContent(
Expand All @@ -143,6 +146,11 @@ fun GoogleMapView(
) {
Text(it.title ?: "Title", color = Color.Blue)
}
Marker(
position = singapore3,
title = "Marker in Singapore",
onClick = markerClick
)
Circle(
center = singapore,
fillColor = MaterialTheme.colors.secondary,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import androidx.compose.runtime.setValue
import com.google.android.gms.maps.CameraUpdate
import com.google.android.gms.maps.CameraUpdateFactory
import com.google.android.gms.maps.GoogleMap
import com.google.android.gms.maps.Projection
import com.google.android.gms.maps.model.CameraPosition
import com.google.android.gms.maps.model.LatLng
import kotlinx.coroutines.CancellableContinuation
Expand Down Expand Up @@ -65,6 +66,13 @@ class CameraPositionState(
var isMoving by mutableStateOf(false)
internal set

/**
* Returns the current [Projection] to be used for converting between screen
* coordinates and lat/lng.
*/
val projection: Projection?
get() = map?.projection

/**
* Local source of truth for the current camera position.
* While [map] is non-null this reflects the current position of [map] as it changes.
Expand Down