Remove unnecessary state duplication for viewPoint
This commit is contained in:
parent
48e425bbae
commit
7939677e5a
@ -59,7 +59,7 @@ fun App() {
|
|||||||
|
|
||||||
MapView(
|
MapView(
|
||||||
mapTileProvider = mapTileProvider,
|
mapTileProvider = mapTileProvider,
|
||||||
initialViewPoint = viewPoint,// use null to infer view point from features
|
initialViewPoint = null,// use null to infer view point from features
|
||||||
config = MapViewConfig(
|
config = MapViewConfig(
|
||||||
onViewChange = { centerCoordinates = focus },
|
onViewChange = { centerCoordinates = focus },
|
||||||
)
|
)
|
||||||
|
@ -62,7 +62,6 @@ public data class MapViewConfig(
|
|||||||
val onViewChange: MapViewPoint.() -> Unit = {},
|
val onViewChange: MapViewPoint.() -> Unit = {},
|
||||||
val onSelect: (GmcRectangle) -> Unit = {},
|
val onSelect: (GmcRectangle) -> Unit = {},
|
||||||
val zoomOnSelect: Boolean = true,
|
val zoomOnSelect: Boolean = true,
|
||||||
val resetViewPoint: Boolean = false,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
|
@ -56,16 +56,8 @@ public actual fun MapView(
|
|||||||
) {
|
) {
|
||||||
var canvasSize by remember { mutableStateOf(DpSize(512.dp, 512.dp)) }
|
var canvasSize by remember { mutableStateOf(DpSize(512.dp, 512.dp)) }
|
||||||
|
|
||||||
var viewPointInternal: MapViewPoint? by remember {
|
var viewPoint: MapViewPoint by remember {
|
||||||
mutableStateOf(null)
|
mutableStateOf(computeViewPoint(canvasSize))
|
||||||
}
|
|
||||||
|
|
||||||
if (config.resetViewPoint) {
|
|
||||||
viewPointInternal = null
|
|
||||||
}
|
|
||||||
|
|
||||||
val viewPoint: MapViewPoint by derivedStateOf {
|
|
||||||
viewPointInternal ?: computeViewPoint(canvasSize)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
val zoom: Int by derivedStateOf {
|
val zoom: Int by derivedStateOf {
|
||||||
@ -153,7 +145,7 @@ public actual fun MapView(
|
|||||||
+dragAmount.y.toDp().value / tileScale
|
+dragAmount.y.toDp().value / tileScale
|
||||||
)
|
)
|
||||||
config.onViewChange(newViewPoint)
|
config.onViewChange(newViewPoint)
|
||||||
viewPointInternal = newViewPoint
|
viewPoint = newViewPoint
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -169,7 +161,7 @@ public actual fun MapView(
|
|||||||
val newViewPoint = gmcBox.computeViewPoint(mapTileProvider).invoke(canvasSize)
|
val newViewPoint = gmcBox.computeViewPoint(mapTileProvider).invoke(canvasSize)
|
||||||
|
|
||||||
config.onViewChange(newViewPoint)
|
config.onViewChange(newViewPoint)
|
||||||
viewPointInternal = newViewPoint
|
viewPoint = newViewPoint
|
||||||
}
|
}
|
||||||
selectRect = null
|
selectRect = null
|
||||||
}
|
}
|
||||||
@ -183,7 +175,7 @@ public actual fun MapView(
|
|||||||
val invariant = DpOffset(xPos.toDp(), yPos.toDp()).toGeodetic()
|
val invariant = DpOffset(xPos.toDp(), yPos.toDp()).toGeodetic()
|
||||||
val newViewPoint = viewPoint.zoom(-change.scrollDelta.y.toDouble() * config.zoomSpeed, invariant)
|
val newViewPoint = viewPoint.zoom(-change.scrollDelta.y.toDouble() * config.zoomSpeed, invariant)
|
||||||
config.onViewChange(newViewPoint)
|
config.onViewChange(newViewPoint)
|
||||||
viewPointInternal = newViewPoint
|
viewPoint = newViewPoint
|
||||||
}.fillMaxSize()
|
}.fillMaxSize()
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user