Skip to content

MapView TimeExtent #194

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 9 commits into from
Nov 14, 2023
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.viewinterop.AndroidView
import com.arcgismaps.ArcGISEnvironment
import com.arcgismaps.mapping.ArcGISMap
import com.arcgismaps.mapping.TimeExtent
import com.arcgismaps.mapping.view.DoubleTapEvent
import com.arcgismaps.mapping.view.DownEvent
import com.arcgismaps.mapping.view.LocationDisplay
Expand Down Expand Up @@ -63,6 +64,7 @@ import kotlinx.coroutines.launch
* @param mapViewInteractionOptions the [MapViewInteractionOptions] used by this composable [com.arcgismaps.toolkit.geocompose.MapView]
* @param viewLabelProperties the [ViewLabelProperties] used by the composable [com.arcgismaps.toolkit.geocompose.MapView]
* @param selectionProperties the [SelectionProperties] used by the composable [com.arcgismaps.toolkit.geocompose.MapView]
* @param timeExtent the [TimeExtent] used by the composable [com.arcgismaps.toolkit.geocompose.MapView]
* @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 onInteractingChanged lambda invoked when the user starts and ends interacting with the composable MapView
Expand All @@ -75,6 +77,7 @@ import kotlinx.coroutines.launch
* @param onLongPress lambda invoked when a user holds a pointer on the composable MapView
* @param onTwoPointerTap lambda invoked when a user taps two pointers on the composable MapView
* @param onPan lambda invoked when a user drags a pointer or pointers across composable MapView
* @param onTimeExtentChanged lambda invoked when the composable MapView [TimeExtent] is changed
* @param overlay the composable overlays to display on top of the composable MapView. Example, a compass, floorfilter etc.
* @since 200.3.0
*/
Expand All @@ -89,6 +92,7 @@ public fun MapView(
mapViewInteractionOptions: MapViewInteractionOptions = MapViewInteractionOptions(),
viewLabelProperties: ViewLabelProperties = ViewLabelProperties(),
selectionProperties: SelectionProperties = SelectionProperties(),
timeExtent: TimeExtent? = null,
onViewpointChanged: (() -> Unit)? = null,
onInteractingChanged: ((isInteracting: Boolean) -> Unit)? = null,
onRotate: ((RotationChangeEvent) -> Unit)? = null,
Expand All @@ -100,6 +104,7 @@ public fun MapView(
onLongPress: ((LongPressEvent) -> Unit)? = null,
onTwoPointerTap: ((TwoPointerTapEvent) -> Unit)? = null,
onPan: ((PanChangeEvent) -> Unit)? = null,
onTimeExtentChanged: ((TimeExtent?) -> Unit)? = null,
overlay: @Composable () -> Unit = {}
) {
val lifecycleOwner = LocalLifecycleOwner.current
Expand All @@ -118,6 +123,7 @@ public fun MapView(
it.labeling = viewLabelProperties
it.wrapAroundMode = wrapAroundMode
it.geometryEditor = geometryEditor
it.setTimeExtent(timeExtent)
})

overlay()
Expand All @@ -143,7 +149,8 @@ public fun MapView(
onDoubleTap,
onLongPress,
onTwoPointerTap,
onPan
onPan,
onTimeExtentChanged,
)

GraphicsOverlaysUpdater(graphicsOverlays, mapView)
Expand All @@ -165,9 +172,11 @@ private fun MapViewEventHandler(
onDoubleTap: ((DoubleTapEvent) -> Unit)?,
onLongPress: ((LongPressEvent) -> Unit)?,
onTwoPointerTap: ((TwoPointerTapEvent) -> Unit)?,
onPan: ((PanChangeEvent) -> Unit)?
onPan: ((PanChangeEvent) -> Unit)?,
onTimeExtentChanged: ((TimeExtent?) -> Unit)?
) {
val currentViewPointChanged by rememberUpdatedState(onViewpointChanged)
val currentTimeExtentChanged by rememberUpdatedState(onTimeExtentChanged)
val currentOnInteractingChanged by rememberUpdatedState(onInteractingChanged)
val currentOnRotate by rememberUpdatedState(onRotate)
val currentOnScale by rememberUpdatedState(onScale)
Expand All @@ -187,6 +196,11 @@ private fun MapViewEventHandler(
}
}
}
launch {
mapView.timeExtent.collect { currentTimeExtent ->
currentTimeExtentChanged?.invoke(currentTimeExtent)
}
}
launch(Dispatchers.Main.immediate) {
mapView.isInteracting.collect { isInteracting ->
currentOnInteractingChanged?.let {
Expand Down