admin管理员组文章数量:1302379
I have a list, and when user selects a element of the list, the detail is a Google map with some markers of that selected item.
If I display it in portrait, everything works, but if I display it in landscape, the list and the detail is visible at once, and then only works correctly one time.
When I select for the first time an item, the map is displayed, and the animation for center the camera works perfectly (I have a launched effect that centers it after markers are loaded). But when I select another item, then, the map doesn't center the camera and the old markers are not deleted, instead of that, the newer ones are painted on the map, and the camera doesn't move.
How to solve this?
My scaffold:
ListDetailPaneScaffold(
modifier = Modifier.fillMaxSize(),
directive = navigator.scaffoldDirective,
value = navigator.scaffoldValue,
listPane = {
AnimatedPane {
LinesList(
lines = uiState.lines,
onItemClick = { index ->
navigator.navigateTo(ListDetailPaneScaffoldRole.Detail, index)
},
)
}
},
detailPane = {
AnimatedPane {
navigator.currentDestination?.content?.let { index ->
vm.selectLine(uiState.lines[index])
MapPanel(mapState = uiState.mapState)
}
}
},
)
My map:
@Composable
fun MapPanel(
mapState: MapState,
modifier: Modifier = Modifier
) {
val showMarkers: Boolean by remember { derivedStateOf { cameraPositionState.position.zoom > minZoomForVisibleMarkers } } // default 15
val boundsBuilder = LatLngBounds.builder()
GoogleMap(
modifier = modifier.fillMaxSize(),
cameraPositionState = cameraPositionState
) {
val bitmapDescriptor: BitmapDescriptor by remember { mutableStateOf(BitmapDescriptorFactory.fromResource(R.drawable.place)) }
for (busStop in mapState.busStops) {
val markerState = rememberMarkerState(
position = LatLng(busStop.lat, busStop.lon)
)
Marker(
state = markerState,
icon = bitmapDescriptor,
visible = showMarkers,
onClick = {
selectBusStop(busStop)
false
}
)
boundsBuilder.include(markerState.position)
}
if (centerInMarkers && mapState.busStops.isNotEmpty()) {
LaunchedEffect(key1 = true ) {
cameraPositionState.animate(
update = CameraUpdateFactory.newLatLngBounds(bounds, 100)
)
}
}
}
}
本文标签: androidDeal with Maps in ListDetailStack Overflow
版权声明:本文标题:android - Deal with Maps in ListDetail - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741705735a2393547.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论