Set location completed

This commit is contained in:
Alexey 2025-09-11 16:23:05 +03:00
commit 215807914a
2 changed files with 8 additions and 0 deletions

View file

@ -172,12 +172,15 @@ fun ToolButton(viewModel: TileViewModel) {
}
}
@Suppress("VariableNeverRead", "AssignedValueIsNeverRead")
@Composable
fun SetLocationDialog(vm: TileViewModel, dialogShown: MutableState<Boolean>) {
var showLocationDialog by dialogShown
if (showLocationDialog) {
var latitudeText by remember { vm.latitudeText }
var longitudeText by remember { vm.longitudeText }
var offsetX by remember { vm.mapOffsetX }
var offsetY by remember { vm.mapOffsetY }
AlertDialog (
onDismissRequest = { showLocationDialog = false },
title = { Text("Input coordinates") },
@ -208,6 +211,9 @@ fun SetLocationDialog(vm: TileViewModel, dialogShown: MutableState<Boolean>) {
val longitude = longitudeText.text.toDoubleOrNull() ?: 0.0
Log.i(TAG, "Lat: %.6f, Lon: %.6f".format(latitude, longitude))
Log.i(TAG, "X = %.6f".format(SphereMercator.mercateLon(longitude, vm.scale.floatValue.toInt(), -TILE_SIZE.toDouble())))
Log.i(TAG, "Y = %.6f".format(SphereMercator.mercateLat(latitude, vm.scale.floatValue.toInt(), -TILE_SIZE.toDouble())))
offsetX = SphereMercator.mercateLon(longitude, vm.scale.floatValue.toInt(), -vm.halvedOffsetX!!.toDouble() - TILE_SIZE).toFloat()
offsetY = SphereMercator.mercateLat(latitude, vm.scale.floatValue.toInt(), -vm.halvedOffsetY!!.toDouble() - TILE_SIZE).toFloat()
}) {
Text("Confirm".uppercase())
} },

View file

@ -54,5 +54,7 @@ class SphereMercator {
fun mercateY(y: Double, level: Int): Double = -sy2lat((y - ((1 shl (level - 1)).toDouble() / 2.0)) * TILE_SIZE, level - 1)
fun mercateLon(longitude: Double, level: Int, offset: Double): Double = lon2sx(longitude + 180.0, level) + offset
fun mercateLat(latitude: Double, level: Int, offset: Double): Double = lat2sy(-latitude, level) + ((1 shl (level - 1)).toDouble() * TILE_SIZE / 2.0) + offset
}
}