KhmParser start
This commit is contained in:
parent
215807914a
commit
996f9b83ca
3 changed files with 57 additions and 26 deletions
27
app/src/main/java/com/mirenkov/ktheightmap/KhmParser.kt
Normal file
27
app/src/main/java/com/mirenkov/ktheightmap/KhmParser.kt
Normal file
|
|
@ -0,0 +1,27 @@
|
||||||
|
package com.mirenkov.ktheightmap
|
||||||
|
|
||||||
|
import android.util.Log
|
||||||
|
import java.io.DataInputStream
|
||||||
|
import java.io.FileInputStream
|
||||||
|
|
||||||
|
class KhmParser {
|
||||||
|
companion object {
|
||||||
|
fun parse(filePath: String) {
|
||||||
|
Log.i(TAG, "start")
|
||||||
|
val dis = DataInputStream(FileInputStream(filePath))
|
||||||
|
with(dis) {
|
||||||
|
Log.i(TAG, "start2")
|
||||||
|
val minLon = readFloat()
|
||||||
|
val minLat = readFloat()
|
||||||
|
val lonPerPixel = readFloat()
|
||||||
|
val latPerPixel = readFloat()
|
||||||
|
val rasterWidth = readInt()
|
||||||
|
val rasterHeight = readInt()
|
||||||
|
Log.i(TAG, "mLon: %.6f, mLat: %.6f, pLon: %.6f, pLat: %.6f, w: %d, h: %d".format(
|
||||||
|
minLon, minLat, lonPerPixel, latPerPixel, rasterWidth, rasterHeight
|
||||||
|
))
|
||||||
|
}
|
||||||
|
Log.i(TAG, "end")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -2,13 +2,10 @@ package com.mirenkov.ktheightmap
|
||||||
|
|
||||||
import android.util.Log
|
import android.util.Log
|
||||||
import androidx.compose.foundation.Canvas
|
import androidx.compose.foundation.Canvas
|
||||||
import androidx.compose.foundation.clickable
|
|
||||||
import androidx.compose.foundation.gestures.detectDragGestures
|
import androidx.compose.foundation.gestures.detectDragGestures
|
||||||
import androidx.compose.foundation.layout.fillMaxSize
|
import androidx.compose.foundation.layout.fillMaxSize
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
import androidx.compose.runtime.MutableFloatState
|
|
||||||
import androidx.compose.runtime.getValue
|
import androidx.compose.runtime.getValue
|
||||||
import androidx.compose.runtime.mutableFloatStateOf
|
|
||||||
import androidx.compose.runtime.saveable.rememberSaveable
|
import androidx.compose.runtime.saveable.rememberSaveable
|
||||||
import androidx.compose.runtime.setValue
|
import androidx.compose.runtime.setValue
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
|
|
|
||||||
|
|
@ -13,6 +13,10 @@ import androidx.compose.foundation.layout.safeDrawingPadding
|
||||||
import androidx.compose.material3.Button
|
import androidx.compose.material3.Button
|
||||||
import androidx.compose.material3.Text
|
import androidx.compose.material3.Text
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
|
import androidx.compose.runtime.MutableState
|
||||||
|
import androidx.compose.runtime.getValue
|
||||||
|
import androidx.compose.runtime.mutableStateOf
|
||||||
|
import androidx.compose.runtime.remember
|
||||||
import androidx.compose.runtime.rememberCoroutineScope
|
import androidx.compose.runtime.rememberCoroutineScope
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.platform.LocalContext
|
import androidx.compose.ui.platform.LocalContext
|
||||||
|
|
@ -31,7 +35,7 @@ import java.util.zip.ZipInputStream
|
||||||
class SettingsActivity : ComponentActivity() {
|
class SettingsActivity : ComponentActivity() {
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
var filePath: String? = null
|
var filePath: MutableState<String?> = mutableStateOf(null)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun filePickerResult(result: FilePickerResult): String? {
|
fun filePickerResult(result: FilePickerResult): String? {
|
||||||
|
|
@ -41,7 +45,7 @@ class SettingsActivity : ComponentActivity() {
|
||||||
} else {
|
} else {
|
||||||
val filePath = result.selectedFilePath
|
val filePath = result.selectedFilePath
|
||||||
filePath?.let {
|
filePath?.let {
|
||||||
if (it.endsWith(".zip"))
|
if (it.endsWith(".zip") || it.endsWith(".khm"))
|
||||||
return filePath
|
return filePath
|
||||||
}
|
}
|
||||||
return null
|
return null
|
||||||
|
|
@ -50,7 +54,7 @@ class SettingsActivity : ComponentActivity() {
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
val launcher = registerForActivityResult(FilePickerResultContracts.PickDocumentFile())
|
val launcher = registerForActivityResult(FilePickerResultContracts.PickDocumentFile())
|
||||||
{ result -> filePath = filePickerResult(result) }
|
{ result -> filePath.value = filePickerResult(result) }
|
||||||
|
|
||||||
enableEdgeToEdge()
|
enableEdgeToEdge()
|
||||||
setContent {
|
setContent {
|
||||||
|
|
@ -70,31 +74,34 @@ class SettingsActivity : ComponentActivity() {
|
||||||
@Composable
|
@Composable
|
||||||
fun SettingsMain(vm: TileViewModel, launcher: ActivityResultLauncher<DocumentFilePickerConfig?>) {
|
fun SettingsMain(vm: TileViewModel, launcher: ActivityResultLauncher<DocumentFilePickerConfig?>) {
|
||||||
val coroutineScope = rememberCoroutineScope()
|
val coroutineScope = rememberCoroutineScope()
|
||||||
|
val filePath by remember { SettingsActivity.filePath }
|
||||||
KtHeightMapTheme {
|
KtHeightMapTheme {
|
||||||
Column(Modifier.fillMaxSize()
|
Column(Modifier.fillMaxSize()
|
||||||
.safeDrawingPadding()) {
|
.safeDrawingPadding()) {
|
||||||
Button(onClick = {
|
Button(
|
||||||
launcher.launch(null)
|
onClick = { launcher.launch(null) }
|
||||||
}) { Text(text = "Select database") }
|
) { Text(text = "Select database") }
|
||||||
Button(onClick = { coroutineScope.launch {
|
Button(
|
||||||
processZip(SettingsActivity.filePath).forEach {
|
onClick = { coroutineScope.launch {
|
||||||
with(vm.repository) {
|
processZip(filePath).forEach {
|
||||||
val t = getTile(it.x, it.y, it.level)
|
with(vm.repository) {
|
||||||
if (t == null) {
|
val t = getTile(it.x, it.y, it.level)
|
||||||
pushTile(it)
|
if (t == null) {
|
||||||
Log.i(TAG, "pushed to db: %d, %d, %d".format(it.level, it.x, it.y))
|
pushTile(it)
|
||||||
}
|
Log.i(TAG, "pushed to db: %d, %d, %d".format(it.level, it.x, it.y))
|
||||||
else
|
}
|
||||||
Log.i(TAG, "found in db: %d, %d, %d".format(t.level, t.x, t.y))
|
else
|
||||||
|
Log.i(TAG, "found in db: %d, %d, %d".format(t.level, t.x, t.y))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
} },
|
||||||
}) { Text(text = "Load database") }
|
) { Text(text = "Load .zip") }
|
||||||
Button(onClick = {
|
Button(
|
||||||
coroutineScope.launch {
|
onClick = { coroutineScope.launch { vm.repository.clearTiles() } },
|
||||||
vm.repository.clearTiles()
|
) { Text(text = "Clear database") }
|
||||||
}
|
Button(
|
||||||
}) { Text(text = "Clear database") }
|
onClick = { filePath?.let { KhmParser.parse(it) } },
|
||||||
|
) { Text(text = "Load .khm") }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue