Compare commits
No commits in common. "4ecdbb1c48ddb2525996654d2f730cace2a9a401" and "b807e46978bf5edb4f71f7d6cca16104d96b978b" have entirely different histories.
4ecdbb1c48
...
b807e46978
3 changed files with 29 additions and 81 deletions
|
|
@ -33,7 +33,6 @@ import com.mirenkov.ktheightmap.Config.Companion.MAP_START_OFFSET_X
|
|||
import com.mirenkov.ktheightmap.Config.Companion.MAP_START_OFFSET_Y
|
||||
import com.mirenkov.ktheightmap.parser.KhmParser
|
||||
import kotlin.math.absoluteValue
|
||||
import kotlin.math.ceil
|
||||
import kotlin.math.floor
|
||||
import kotlin.math.min
|
||||
import kotlin.math.pow
|
||||
|
|
@ -258,7 +257,7 @@ fun DrawScope.drawPointInfo(
|
|||
val latDiff = lat - pointLat
|
||||
val lonDiff = lon - pointLon
|
||||
val distance = sqrt((latDiff).pow(2) + (lonDiff).pow(2))
|
||||
val valuesCount = min(ceil(distance / valueDistance).toInt(), 1000)
|
||||
val valuesCount = min(floor(distance / valueDistance).toInt(),1000)
|
||||
val array: Array<Pair<Float, Float>> = Array(valuesCount) { step ->
|
||||
val interCoef = 1F - step.toFloat() / valuesCount
|
||||
Pair(lon - lonDiff * interCoef, lat - latDiff * interCoef)
|
||||
|
|
|
|||
|
|
@ -1,6 +1,5 @@
|
|||
package com.mirenkov.ktheightmap
|
||||
|
||||
import android.annotation.SuppressLint
|
||||
import android.app.Application
|
||||
import android.os.Bundle
|
||||
import android.widget.Toast
|
||||
|
|
@ -9,27 +8,16 @@ import androidx.activity.compose.setContent
|
|||
import androidx.activity.enableEdgeToEdge
|
||||
import androidx.activity.result.ActivityResultLauncher
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.Row
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.foundation.layout.safeDrawingPadding
|
||||
import androidx.compose.material3.Button
|
||||
import androidx.compose.material3.HorizontalDivider
|
||||
import androidx.compose.material3.Scaffold
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.runtime.rememberCoroutineScope
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import androidx.compose.ui.text.AnnotatedString
|
||||
import androidx.compose.ui.text.SpanStyle
|
||||
import androidx.compose.ui.text.buildAnnotatedString
|
||||
import androidx.compose.ui.text.font.FontWeight
|
||||
import androidx.compose.ui.text.withStyle
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.compose.ui.unit.sp
|
||||
import androidx.lifecycle.viewmodel.compose.LocalViewModelStoreOwner
|
||||
import androidx.lifecycle.viewmodel.compose.viewModel
|
||||
import com.mirenkov.ktheightmap.parser.KhmParser
|
||||
|
|
@ -61,76 +49,41 @@ class SettingsActivity : ComponentActivity() {
|
|||
}
|
||||
}
|
||||
|
||||
@SuppressLint("ShowToast")
|
||||
@Composable
|
||||
fun SettingsMain(vm: TileViewModel, launcher: ActivityResultLauncher<DocumentFilePickerConfig?>) {
|
||||
|
||||
val coroutineScope = rememberCoroutineScope()
|
||||
val filePath by remember { FileLoader.filePath }
|
||||
val ctx = LocalContext.current
|
||||
val loadToast = Toast.makeText(ctx, "File successfully loaded.", Toast.LENGTH_LONG)
|
||||
val clearTilesToast = Toast.makeText(ctx, "Tiles removed from database.", Toast.LENGTH_LONG)
|
||||
val clearHeightToast = Toast.makeText(ctx, "Height data removed.", Toast.LENGTH_LONG)
|
||||
val fileSelectorRow = @Composable () {
|
||||
Row(Modifier.fillMaxWidth()) {
|
||||
Button({ launcher.launch(null) }) { Text("Select") }
|
||||
Text("Selected file: none", Modifier.padding(8.dp, 0.dp).align(Alignment.CenterVertically))
|
||||
}
|
||||
}
|
||||
val toast = Toast.makeText(ctx, "File parsed.", Toast.LENGTH_LONG)
|
||||
KtHeightMapTheme {
|
||||
Scaffold { paddingValues ->
|
||||
Column(Modifier.padding(paddingValues)) {
|
||||
LabeledSection("Select file:", Modifier.padding(24.dp, 8.dp)) {
|
||||
fileSelectorRow()
|
||||
}
|
||||
LabeledSection("Load file as...", Modifier.padding(24.dp, 8.dp)) {
|
||||
Button({ filePath?.let {
|
||||
Column(Modifier.fillMaxSize()
|
||||
.safeDrawingPadding()) {
|
||||
Button({ launcher.launch(null) }) { Text("Select file") }
|
||||
Button({
|
||||
filePath?.let {
|
||||
coroutineScope.launch(Dispatchers.IO) {
|
||||
SasSQLiteParser.processZip(it, vm.repository, ctx)
|
||||
coroutineScope.launch(Dispatchers.Main) { loadToast.show() }
|
||||
coroutineScope.launch(Dispatchers.Main) { toast.show() }
|
||||
}
|
||||
} }) { Text("SQLite (.zip)") }
|
||||
Button({ filePath?.let {
|
||||
} }
|
||||
) { Text("Load SQLite") }
|
||||
Button({
|
||||
filePath?.let {
|
||||
coroutineScope.launch(Dispatchers.IO) {
|
||||
SasJPEGParser.processZip(it, vm.repository)
|
||||
coroutineScope.launch(Dispatchers.Main) { loadToast.show() }
|
||||
coroutineScope.launch(Dispatchers.Main) { toast.show() }
|
||||
}
|
||||
} }) { Text("JPEG (.zip)") }
|
||||
Button({ filePath?.let {
|
||||
}
|
||||
},
|
||||
) { Text("Load JPEG") }
|
||||
Button({
|
||||
filePath?.let {
|
||||
KhmParser.load(it, ctx)
|
||||
loadToast.show()
|
||||
} }) { Text("Height data (.khm)") }
|
||||
}
|
||||
LabeledSection("Clear...", Modifier.padding(24.dp, 8.dp)) {
|
||||
Button({ coroutineScope.launch {
|
||||
vm.repository.clearTiles()
|
||||
clearTilesToast.show()
|
||||
} }) { Text("Tile data") }
|
||||
Button({
|
||||
KhmParser.clear(ctx)
|
||||
clearHeightToast.show()
|
||||
}) { Text("Height data") }
|
||||
}
|
||||
}
|
||||
toast.show()
|
||||
} },
|
||||
) { Text("Load KHM") }
|
||||
Button({ coroutineScope.launch { vm.repository.clearTiles() } }) { Text("Clear tiles") }
|
||||
Button({ KhmParser.clear(ctx) }) { Text("Clear KHM") }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun labelString(text: String): AnnotatedString {
|
||||
return buildAnnotatedString {
|
||||
withStyle(SpanStyle(fontWeight = FontWeight.Bold, fontSize = 24.sp)) {
|
||||
append(text)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun LabeledSection(text: String, modifier: Modifier = Modifier, content: @Composable () -> Unit) {
|
||||
Column(modifier) {
|
||||
Text(labelString(text))
|
||||
HorizontalDivider()
|
||||
Column(
|
||||
modifier = modifier.fillMaxWidth()
|
||||
) { content() }
|
||||
}
|
||||
}
|
||||
|
|
@ -122,14 +122,10 @@ class KhmParser {
|
|||
|
||||
return Pair(
|
||||
UShortArray(coords.size) { i ->
|
||||
when {
|
||||
(cutOffsets[i] > 0) -> {
|
||||
dis.skipBytes(cutOffsets[i])
|
||||
dis.readUnsignedShort().toUShort()
|
||||
}
|
||||
(cutOffsets[i] == 0) -> {dis.readUnsignedShort().toUShort()}
|
||||
else -> 0u
|
||||
} },
|
||||
if (cutOffsets[i] > 0) {
|
||||
dis.skipBytes(cutOffsets[i])
|
||||
dis.readUnsignedShort().toUShort()
|
||||
} else 0u },
|
||||
if (reversed) coords else coords.reversed().toTypedArray())
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue