From 215807914a325d6f25fe2d7ba46f37190bd049dc Mon Sep 17 00:00:00 2001 From: 2ndbeam <2ndbeam@disroot.org> Date: Thu, 11 Sep 2025 16:23:05 +0300 Subject: [PATCH] Set location completed --- app/src/main/java/com/mirenkov/ktheightmap/MainActivity.kt | 6 ++++++ .../main/java/com/mirenkov/ktheightmap/SphereMercator.kt | 2 ++ 2 files changed, 8 insertions(+) diff --git a/app/src/main/java/com/mirenkov/ktheightmap/MainActivity.kt b/app/src/main/java/com/mirenkov/ktheightmap/MainActivity.kt index 4deea14..79f2f15 100644 --- a/app/src/main/java/com/mirenkov/ktheightmap/MainActivity.kt +++ b/app/src/main/java/com/mirenkov/ktheightmap/MainActivity.kt @@ -172,12 +172,15 @@ fun ToolButton(viewModel: TileViewModel) { } } +@Suppress("VariableNeverRead", "AssignedValueIsNeverRead") @Composable fun SetLocationDialog(vm: TileViewModel, dialogShown: MutableState) { 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) { 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()) } }, diff --git a/app/src/main/java/com/mirenkov/ktheightmap/SphereMercator.kt b/app/src/main/java/com/mirenkov/ktheightmap/SphereMercator.kt index 4d44954..d57e457 100644 --- a/app/src/main/java/com/mirenkov/ktheightmap/SphereMercator.kt +++ b/app/src/main/java/com/mirenkov/ktheightmap/SphereMercator.kt @@ -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 } } \ No newline at end of file