Skip to content

MapView Rotation & Scale #195

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Nov 13, 2023
Merged
Changes from 4 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 @@ -70,6 +70,8 @@ import kotlinx.coroutines.launch
* @param backgroundGrid the default color and context grid behind the map surface
* @param wrapAroundMode the [WrapAroundMode] to specify whether continuous panning across the international date line is enabled
* @param onViewpointChanged lambda invoked when the viewpoint of the composable MapView has changed
* @param onMapRotationChanged lambda invoked with the composable MapView's current rotation
* @param onMapScaleChanged lambda invoked with the composable MapView's current scale
* @param onInteractingChanged lambda invoked when the user starts and ends interacting with the composable MapView
* @param onRotate lambda invoked when a user performs a rotation gesture on the composable MapView
* @param onScale lambda invoked when a user performs a pinch gesture on the composable MapView
Expand Down Expand Up @@ -98,6 +100,8 @@ public fun MapView(
grid: Grid? = null,
backgroundGrid: BackgroundGrid = BackgroundGrid(),
onViewpointChanged: (() -> Unit)? = null,
onMapRotationChanged: ((Double) -> Unit)? = null,
onMapScaleChanged: ((Double) -> Unit)? = null,
onInteractingChanged: ((isInteracting: Boolean) -> Unit)? = null,
onRotate: ((RotationChangeEvent) -> Unit)? = null,
onScale: ((ScaleChangeEvent) -> Unit)? = null,
Expand Down Expand Up @@ -145,6 +149,8 @@ public fun MapView(
MapViewEventHandler(
mapView,
onViewpointChanged,
onMapRotationChanged,
onMapScaleChanged,
onInteractingChanged,
onRotate,
onScale,
Expand All @@ -168,6 +174,8 @@ public fun MapView(
private fun MapViewEventHandler(
mapView: MapView,
onViewpointChanged: (() -> Unit)?,
onMapRotationChanged: ((Double) -> Unit)?,
onMapScaleChanged: ((Double) -> Unit)?,
onInteractingChanged: ((isInteracting: Boolean) -> Unit)?,
onRotate: ((RotationChangeEvent) -> Unit)?,
onScale: ((ScaleChangeEvent) -> Unit)?,
Expand All @@ -181,6 +189,8 @@ private fun MapViewEventHandler(
onDrawStatusChanged: ((DrawStatus) -> Unit)?
) {
val currentViewPointChanged by rememberUpdatedState(onViewpointChanged)
val currentOnMapRotationChanged by rememberUpdatedState(onMapRotationChanged)
val currentOnMapScaleChanged by rememberUpdatedState(onMapScaleChanged)
val currentOnInteractingChanged by rememberUpdatedState(onInteractingChanged)
val currentOnRotate by rememberUpdatedState(onRotate)
val currentOnScale by rememberUpdatedState(onScale)
Expand All @@ -199,6 +209,16 @@ private fun MapViewEventHandler(
currentViewPointChanged?.invoke()
}
}
launch {
mapView.mapRotation.collect { mapRotation ->
currentOnMapRotationChanged?.invoke(mapRotation)
}
}
launch {
mapView.mapScale.collect { mapScale ->
currentOnMapScaleChanged?.invoke(mapScale)
}
}
launch(Dispatchers.Main.immediate) {
mapView.isInteracting.collect { isInteracting ->
currentOnInteractingChanged?.invoke(isInteracting)
Expand Down