Add rectangle override for map component builder
This commit is contained in:
parent
1808a9b7d3
commit
4cabfcf16f
@ -10,7 +10,7 @@ val ktorVersion by extra("2.0.3")
|
|||||||
|
|
||||||
allprojects {
|
allprojects {
|
||||||
group = "center.sciprog"
|
group = "center.sciprog"
|
||||||
version = "0.1.0-dev-4"
|
version = "0.1.0-dev-5"
|
||||||
}
|
}
|
||||||
|
|
||||||
ksciencePublish{
|
ksciencePublish{
|
||||||
|
@ -35,12 +35,12 @@ private fun GeodeticMapCoordinates.toShortString(): String =
|
|||||||
fun App() {
|
fun App() {
|
||||||
MaterialTheme {
|
MaterialTheme {
|
||||||
//create a view point
|
//create a view point
|
||||||
val viewPoint = remember {
|
// val viewPoint = remember {
|
||||||
MapViewPoint(
|
// MapViewPoint(
|
||||||
GeodeticMapCoordinates.ofDegrees(55.7558, 37.6173),
|
// GeodeticMapCoordinates.ofDegrees(55.7558, 37.6173),
|
||||||
8.0
|
// 8.0
|
||||||
)
|
// )
|
||||||
}
|
// }
|
||||||
|
|
||||||
val scope = rememberCoroutineScope()
|
val scope = rememberCoroutineScope()
|
||||||
val mapTileProvider = remember {
|
val mapTileProvider = remember {
|
||||||
|
@ -101,20 +101,29 @@ private fun prepareConfig(initialConfig: MapViewConfig, featureBuilder: MapFeatu
|
|||||||
|
|
||||||
internal fun GmcRectangle.computeViewPoint(
|
internal fun GmcRectangle.computeViewPoint(
|
||||||
mapTileProvider: MapTileProvider,
|
mapTileProvider: MapTileProvider,
|
||||||
): (canvasSize: DpSize) -> MapViewPoint = { canvasSize ->
|
canvasSize: DpSize,
|
||||||
|
): MapViewPoint {
|
||||||
val zoom = log2(
|
val zoom = log2(
|
||||||
min(
|
min(
|
||||||
canvasSize.width.value / longitudeDelta.radians.value,
|
canvasSize.width.value / longitudeDelta.radians.value,
|
||||||
canvasSize.height.value / latitudeDelta.radians.value
|
canvasSize.height.value / latitudeDelta.radians.value
|
||||||
) * PI / mapTileProvider.tileSize
|
) * PI / mapTileProvider.tileSize
|
||||||
)
|
)
|
||||||
MapViewPoint(center, zoom)
|
return MapViewPoint(center, zoom)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Draw a map using convenient parameters. If neither [initialViewPoint], noe [initialRectangle] is defined,
|
||||||
|
* use map features to infer view region.
|
||||||
|
* @param initialViewPoint The view point of the map using center and zoom. Is used if provided
|
||||||
|
* @param initialRectangle The rectangle to be used for view point computation. Used if [initialViewPoint] is not defined.
|
||||||
|
* @param buildFeatures - a builder for features
|
||||||
|
*/
|
||||||
@Composable
|
@Composable
|
||||||
public fun MapView(
|
public fun MapView(
|
||||||
mapTileProvider: MapTileProvider,
|
mapTileProvider: MapTileProvider,
|
||||||
initialViewPoint: MapViewPoint? = null,
|
initialViewPoint: MapViewPoint? = null,
|
||||||
|
initialRectangle: GmcRectangle? = null,
|
||||||
config: MapViewConfig = MapViewConfig(),
|
config: MapViewConfig = MapViewConfig(),
|
||||||
modifier: Modifier = Modifier.fillMaxSize(),
|
modifier: Modifier = Modifier.fillMaxSize(),
|
||||||
buildFeatures: @Composable (MapFeatureBuilder.() -> Unit) = {},
|
buildFeatures: @Composable (MapFeatureBuilder.() -> Unit) = {},
|
||||||
@ -130,15 +139,10 @@ public fun MapView(
|
|||||||
MapView(
|
MapView(
|
||||||
mapTileProvider,
|
mapTileProvider,
|
||||||
{ canvasSize ->
|
{ canvasSize ->
|
||||||
initialViewPoint ?: features.values.computeBoundingBox(1.0)?.let { box ->
|
initialViewPoint
|
||||||
val zoom = log2(
|
?: initialRectangle?.computeViewPoint(mapTileProvider, canvasSize)
|
||||||
min(
|
?: features.values.computeBoundingBox(1.0)?.computeViewPoint(mapTileProvider, canvasSize)
|
||||||
canvasSize.width.value / box.longitudeDelta.radians.value,
|
?: MapViewPoint(GeodeticMapCoordinates(0.0.radians, 0.0.radians), 1.0)
|
||||||
canvasSize.height.value / box.latitudeDelta.radians.value
|
|
||||||
) * PI / mapTileProvider.tileSize
|
|
||||||
)
|
|
||||||
MapViewPoint(box.center, zoom)
|
|
||||||
} ?: MapViewPoint(GeodeticMapCoordinates(0.0.radians, 0.0.radians), 1.0)
|
|
||||||
},
|
},
|
||||||
features,
|
features,
|
||||||
newConfig,
|
newConfig,
|
||||||
|
@ -158,7 +158,7 @@ public actual fun MapView(
|
|||||||
)
|
)
|
||||||
config.onSelect(gmcBox)
|
config.onSelect(gmcBox)
|
||||||
if (config.zoomOnSelect) {
|
if (config.zoomOnSelect) {
|
||||||
val newViewPoint = gmcBox.computeViewPoint(mapTileProvider).invoke(canvasSize)
|
val newViewPoint = gmcBox.computeViewPoint(mapTileProvider, canvasSize)
|
||||||
|
|
||||||
config.onViewChange(newViewPoint)
|
config.onViewChange(newViewPoint)
|
||||||
viewPoint = newViewPoint
|
viewPoint = newViewPoint
|
||||||
|
Loading…
Reference in New Issue
Block a user