MERCATE LOOOOOOOOOOOOOOOOOOOOOON
This commit is contained in:
parent
7a83286681
commit
f089879d1b
4 changed files with 27 additions and 15 deletions
|
|
@ -156,7 +156,6 @@ fun ToolButton(viewModel: TileViewModel) {
|
|||
DropdownMenuItem(
|
||||
text = { Text("Set location") },
|
||||
onClick = {
|
||||
expanded = false
|
||||
dialogShown.value = true
|
||||
}
|
||||
)
|
||||
|
|
@ -205,9 +204,10 @@ fun SetLocationDialog(vm: TileViewModel, dialogShown: MutableState<Boolean>) {
|
|||
}
|
||||
},
|
||||
confirmButton = { TextButton(onClick = {
|
||||
Log.i(TAG, "Lat: %.6f, Lon: %.6f".format(
|
||||
latitudeText.text.toDoubleOrNull() ?: 0.0, longitudeText.text.toDoubleOrNull() ?: 0.0
|
||||
))
|
||||
val latitude = latitudeText.text.toDoubleOrNull() ?: 0.0
|
||||
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())))
|
||||
}) {
|
||||
Text("Confirm".uppercase())
|
||||
} },
|
||||
|
|
|
|||
|
|
@ -51,6 +51,13 @@ fun MapCanvas(
|
|||
}
|
||||
}
|
||||
) {
|
||||
if (viewModel.halvedOffsetX == null) {
|
||||
viewModel.halvedOffsetX = size.width / 2
|
||||
viewModel.halvedOffsetY = size.height / 2
|
||||
}
|
||||
val halvedX = viewModel.halvedOffsetX!!
|
||||
val halvedY = viewModel.halvedOffsetY!!
|
||||
|
||||
drawRect(
|
||||
color = backColor,
|
||||
size = size
|
||||
|
|
@ -67,8 +74,8 @@ fun MapCanvas(
|
|||
|
||||
if (levelDiff < 0) {
|
||||
repeat (levelDiff.absoluteValue) {
|
||||
offsetX -= size.width / 2F + TILE_SIZE
|
||||
offsetY -= size.height / 2F + TILE_SIZE
|
||||
offsetX -= halvedX + TILE_SIZE
|
||||
offsetY -= halvedY + TILE_SIZE
|
||||
offsetX /= 2F
|
||||
offsetY /= 2F
|
||||
}
|
||||
|
|
@ -76,15 +83,15 @@ fun MapCanvas(
|
|||
repeat (levelDiff) {
|
||||
offsetX *= 2F
|
||||
offsetY *= 2F
|
||||
offsetX += size.width / 2F + TILE_SIZE
|
||||
offsetY += size.height / 2F + TILE_SIZE
|
||||
offsetX += halvedX + TILE_SIZE
|
||||
offsetY += halvedY + TILE_SIZE
|
||||
}
|
||||
}
|
||||
val tileOffsetX = (offsetX / TILE_SIZE).toInt()
|
||||
val tileOffsetY = (offsetY / TILE_SIZE).toInt()
|
||||
|
||||
val centerTileX = (1 + (offsetX + size.width / 2) / TILE_SIZE).toDouble()
|
||||
val centerTileY = (1 + (offsetY + size.height / 2) / TILE_SIZE).toDouble()
|
||||
val centerTileX = (1 + (offsetX + halvedX) / TILE_SIZE).toDouble()
|
||||
val centerTileY = (1 + (offsetY + halvedY) / TILE_SIZE).toDouble()
|
||||
|
||||
val strippedOffsetX = offsetX % TILE_SIZE
|
||||
val strippedOffsetY = offsetY % TILE_SIZE
|
||||
|
|
@ -101,7 +108,7 @@ fun MapCanvas(
|
|||
val crossRadius = 24F
|
||||
|
||||
val additionalSize = if (debug) 96F else 0F
|
||||
val latLonSize = Size(196F, 96F + additionalSize)
|
||||
val latLonSize = Size(216F, 96F + additionalSize)
|
||||
val latLonOffset = Offset(16F, 16F)
|
||||
|
||||
for (cellX in 0 .. gridWidth + 2) {
|
||||
|
|
@ -148,10 +155,10 @@ fun MapCanvas(
|
|||
}
|
||||
|
||||
val path = Path()
|
||||
path.moveTo(size.width / 2 - crossRadius, size.height / 2)
|
||||
path.lineTo(size.width / 2 + crossRadius, size.height / 2)
|
||||
path.moveTo(size.width / 2, size.height / 2 - crossRadius)
|
||||
path.lineTo(size.width / 2, size.height / 2 + crossRadius)
|
||||
path.moveTo(halvedX - crossRadius, halvedY)
|
||||
path.lineTo(halvedX + crossRadius, halvedY)
|
||||
path.moveTo(halvedX, halvedY - crossRadius)
|
||||
path.lineTo(halvedX, halvedY + crossRadius)
|
||||
path.close()
|
||||
|
||||
drawPath(
|
||||
|
|
|
|||
|
|
@ -52,5 +52,7 @@ class SphereMercator {
|
|||
fun mercateX(x: Double, level: Int): Double = sx2lon((x * TILE_SIZE), level) - 180.0
|
||||
|
||||
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
|
||||
}
|
||||
}
|
||||
|
|
@ -19,6 +19,9 @@ class TileViewModel(application: Application): ViewModel() {
|
|||
val mapOffsetY = mutableFloatStateOf(-1157.2814F)
|
||||
val scale = mutableFloatStateOf(1F)
|
||||
|
||||
var halvedOffsetX: Float? = null
|
||||
var halvedOffsetY: Float? = null
|
||||
|
||||
init {
|
||||
val tileDb = TileDB.getInstance(application)
|
||||
val tileDao = tileDb.tileDao()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue