little refactoring

This commit is contained in:
Alexey 2025-08-25 15:41:31 +03:00
commit 3f2b3eec45
3 changed files with 12 additions and 7 deletions

View file

@ -91,7 +91,8 @@ fun MapCanvas(
val tileY = tileOffsetY + cellY
val localOffsetY = TILE_SIZE * (cellY - 1)
val bitmap = tiles.find { it.x == tileX && it.y == tileY && it.level == level }?.toBitmap()
val tile = tiles.find { it.x == tileX && it.y == tileY && it.level == level }!!
val bitmap = tile.toBitmap()
val totalOffset = Offset(localOffsetX, localOffsetY) - offset
bitmap?.let {
@ -114,10 +115,8 @@ fun MapCanvas(
text = buildAnnotatedString {
withStyle(ParagraphStyle(textAlign = TextAlign.Center)) {
withStyle(SpanStyle(color = gridColor)) {
val mapSize = (1 shl (level - 1)).toDouble()
val mappedY = (tileY.toDouble() - (mapSize / 2.0))
val mercX = SphereMercator.sx2lon((tileX * TILE_SIZE).toDouble(), level) - 180.0
val mercY = -SphereMercator.sy2lat(mappedY * TILE_SIZE, level - 1)
val mercX = tile.mercateX()
val mercY = tile.mercateY()
append("%.6f, %.6f,\n%d, %d".format(mercX, mercY, tileX, tileY))
}
}
@ -125,6 +124,8 @@ fun MapCanvas(
topLeft = totalOffset,
size = Size(TILE_SIZE, TILE_SIZE)
)
}
}
}

View file

@ -46,4 +46,8 @@ class Tile {
bitmap = BitmapFactory.decodeByteArray(ba, 0, ba.size)
return bitmap
}
fun mercateX(): Double = SphereMercator.sx2lon((x * TILE_SIZE).toDouble(), level) - 180.0
fun mercateY(): Double = -SphereMercator.sy2lat((y.toDouble() - ((1 shl (level - 1)).toDouble() / 2.0)) * TILE_SIZE, level - 1)
}