small autozoom fix
This commit is contained in:
parent
c7d1797617
commit
7ada7f85f2
@ -49,7 +49,7 @@ fun MapView(
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
internal fun GmcBox.getComputeViewPoint(mapTileProvider: MapTileProvider): (canvasSize: DpSize) -> MapViewPoint = { canvasSize ->
|
internal fun GmcBox.computeViewPoint(mapTileProvider: MapTileProvider): (canvasSize: DpSize) -> MapViewPoint = { canvasSize ->
|
||||||
val zoom = log2(
|
val zoom = log2(
|
||||||
min(
|
min(
|
||||||
canvasSize.width.value / width,
|
canvasSize.width.value / width,
|
||||||
@ -72,7 +72,7 @@ fun MapView(
|
|||||||
featuresBuilder.buildFeatures()
|
featuresBuilder.buildFeatures()
|
||||||
MapView(
|
MapView(
|
||||||
mapTileProvider,
|
mapTileProvider,
|
||||||
box.getComputeViewPoint(mapTileProvider),
|
box.computeViewPoint(mapTileProvider),
|
||||||
featuresBuilder.build(),
|
featuresBuilder.build(),
|
||||||
config,
|
config,
|
||||||
modifier
|
modifier
|
||||||
|
@ -17,7 +17,7 @@ import androidx.compose.ui.graphics.toArgb
|
|||||||
import androidx.compose.ui.input.pointer.*
|
import androidx.compose.ui.input.pointer.*
|
||||||
import androidx.compose.ui.unit.*
|
import androidx.compose.ui.unit.*
|
||||||
import centre.sciprog.maps.*
|
import centre.sciprog.maps.*
|
||||||
import io.ktor.utils.io.CancellationException
|
import kotlinx.coroutines.CancellationException
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
import mu.KotlinLogging
|
import mu.KotlinLogging
|
||||||
import org.jetbrains.skia.Font
|
import org.jetbrains.skia.Font
|
||||||
@ -59,9 +59,12 @@ actual fun MapView(
|
|||||||
) {
|
) {
|
||||||
var canvasSize by remember { mutableStateOf(DpSize(512.dp, 512.dp)) }
|
var canvasSize by remember { mutableStateOf(DpSize(512.dp, 512.dp)) }
|
||||||
|
|
||||||
var viewPointOverride: MapViewPoint? by remember {
|
var viewPointInternal: MapViewPoint? by remember {
|
||||||
mutableStateOf(
|
mutableStateOf(null)
|
||||||
if (config.inferViewBoxFromFeatures) {
|
}
|
||||||
|
|
||||||
|
val viewPoint: MapViewPoint by derivedStateOf {
|
||||||
|
viewPointInternal ?: if (config.inferViewBoxFromFeatures) {
|
||||||
features.values.computeBoundingBox(1)?.let { box ->
|
features.values.computeBoundingBox(1)?.let { box ->
|
||||||
val zoom = log2(
|
val zoom = log2(
|
||||||
min(
|
min(
|
||||||
@ -70,15 +73,12 @@ actual fun MapView(
|
|||||||
) * PI / mapTileProvider.tileSize
|
) * PI / mapTileProvider.tileSize
|
||||||
)
|
)
|
||||||
MapViewPoint(box.center, zoom)
|
MapViewPoint(box.center, zoom)
|
||||||
}
|
} ?: computeViewPoint(canvasSize)
|
||||||
} else {
|
} else {
|
||||||
null
|
computeViewPoint(canvasSize)
|
||||||
}
|
}
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
val viewPoint by derivedStateOf { viewPointOverride ?: computeViewPoint(canvasSize) }
|
|
||||||
|
|
||||||
val zoom: Int by derivedStateOf { floor(viewPoint.zoom).toInt() }
|
val zoom: Int by derivedStateOf { floor(viewPoint.zoom).toInt() }
|
||||||
|
|
||||||
val tileScale: Double by derivedStateOf { 2.0.pow(viewPoint.zoom - zoom) }
|
val tileScale: Double by derivedStateOf { 2.0.pow(viewPoint.zoom - zoom) }
|
||||||
@ -131,11 +131,11 @@ actual fun MapView(
|
|||||||
rect.bottomRight.toDpOffset().toGeodetic()
|
rect.bottomRight.toDpOffset().toGeodetic()
|
||||||
)
|
)
|
||||||
config.onSelect(gmcBox)
|
config.onSelect(gmcBox)
|
||||||
if(config.zoomOnSelect) {
|
if (config.zoomOnSelect) {
|
||||||
val newViewPoint = gmcBox.getComputeViewPoint(mapTileProvider).invoke(canvasSize)
|
val newViewPoint = gmcBox.computeViewPoint(mapTileProvider).invoke(canvasSize)
|
||||||
|
|
||||||
config.onViewChange(newViewPoint)
|
config.onViewChange(newViewPoint)
|
||||||
viewPointOverride = newViewPoint
|
viewPointInternal = newViewPoint
|
||||||
}
|
}
|
||||||
selectRect = null
|
selectRect = null
|
||||||
}
|
}
|
||||||
@ -150,7 +150,7 @@ actual fun MapView(
|
|||||||
+dragAmount.y.toDp().value / tileScale
|
+dragAmount.y.toDp().value / tileScale
|
||||||
)
|
)
|
||||||
config.onViewChange(newViewPoint)
|
config.onViewChange(newViewPoint)
|
||||||
viewPointOverride = newViewPoint
|
viewPointInternal = newViewPoint
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -164,7 +164,7 @@ 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)
|
||||||
viewPointOverride = newViewPoint
|
viewPointInternal = newViewPoint
|
||||||
}.fillMaxSize()
|
}.fillMaxSize()
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user