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 @@ -34,6 +34,7 @@ import androidx.compose.ui.viewinterop.AndroidView
import com.arcgismaps.ArcGISEnvironment
import com.arcgismaps.geometry.SpatialReference
import com.arcgismaps.mapping.ArcGISMap
import com.arcgismaps.mapping.TimeExtent
import com.arcgismaps.mapping.view.BackgroundGrid
import com.arcgismaps.mapping.view.DoubleTapEvent
import com.arcgismaps.mapping.view.DownEvent
Expand Down Expand Up @@ -74,6 +75,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 attributionState specifies the attribution bar's visibility, text changed and layout changed events
* @param timeExtent the [TimeExtent] used by the composable MapView
* @param onTimeExtentChanged lambda invoked when the composable MapView's [TimeExtent] is changed
* @param onViewpointChanged lambda invoked when the viewpoint of the composable MapView has changed
* @param onNavigationChanged lambda invoked when the navigation status of the composable MapView has changed
* @param onMapRotationChanged lambda invoked when the rotation of this composable MapView has changed
Expand Down Expand Up @@ -108,6 +111,8 @@ public fun MapView(
backgroundGrid: BackgroundGrid = BackgroundGrid(),
wrapAroundMode: WrapAroundMode = WrapAroundMode.EnabledWhenSupported,
attributionState: AttributionState = AttributionState(),
timeExtent: TimeExtent? = null,
onTimeExtentChanged: ((TimeExtent?) -> Unit)? = null,
onViewpointChanged: (() -> Unit)? = null,
onNavigationChanged: ((isNavigating: Boolean) -> Unit)? = null,
onMapRotationChanged: ((Double) -> Unit)? = null,
Expand All @@ -134,15 +139,16 @@ public fun MapView(
modifier = modifier.semantics { contentDescription = "MapView" },
factory = { mapView },
update = {
it.map = arcGISMap
it.selectionProperties = selectionProperties
it.interactionOptions = mapViewInteractionOptions
it.locationDisplay = locationDisplay
it.labeling = viewLabelProperties
it.wrapAroundMode = wrapAroundMode
it.geometryEditor = geometryEditor
it.grid = grid
it.backgroundGrid = backgroundGrid
it.map = arcGISMap
it.selectionProperties = selectionProperties
it.interactionOptions = mapViewInteractionOptions
it.locationDisplay = locationDisplay
it.labeling = viewLabelProperties
it.wrapAroundMode = wrapAroundMode
it.geometryEditor = geometryEditor
it.grid = grid
it.backgroundGrid = backgroundGrid
it.setTimeExtent(timeExtent)
})

DisposableEffect(Unit) {
Expand Down Expand Up @@ -175,6 +181,7 @@ public fun MapView(

MapViewEventHandler(
mapView,
onTimeExtentChanged,
onViewpointChanged,
onNavigationChanged,
onMapRotationChanged,
Expand Down Expand Up @@ -225,6 +232,7 @@ private fun AttributionStateHandler(mapView: MapView, attributionState: Attribut
@Composable
private fun MapViewEventHandler(
mapView: MapView,
onTimeExtentChanged: ((TimeExtent?) -> Unit)?,
onViewpointChanged: (() -> Unit)?,
onNavigationChanged: ((isNavigating: Boolean) -> Unit)?,
onMapRotationChanged: ((Double) -> Unit)?,
Expand All @@ -242,6 +250,7 @@ private fun MapViewEventHandler(
onPan: ((PanChangeEvent) -> Unit)?,
onDrawStatusChanged: ((DrawStatus) -> Unit)?
) {
val currentTimeExtentChanged by rememberUpdatedState(onTimeExtentChanged)
val currentViewPointChanged by rememberUpdatedState(onViewpointChanged)
val currentOnNavigationChanged by rememberUpdatedState(onNavigationChanged)
val currentOnMapRotationChanged by rememberUpdatedState(onMapRotationChanged)
Expand All @@ -260,6 +269,11 @@ private fun MapViewEventHandler(
val currentOnDrawStatusChanged by rememberUpdatedState(onDrawStatusChanged)

LaunchedEffect(Unit) {
launch {
mapView.timeExtent.collect { currentTimeExtent ->
currentTimeExtentChanged?.invoke(currentTimeExtent)
}
}
launch {
mapView.viewpointChanged.collect {
currentViewPointChanged?.invoke()
Expand Down