2022-07-23 10:58:16 +03:00
|
|
|
package center.sciprog.maps.compose
|
2022-07-10 22:37:07 +03:00
|
|
|
|
|
|
|
import androidx.compose.ui.graphics.ImageBitmap
|
2022-07-15 09:30:36 +03:00
|
|
|
import kotlinx.coroutines.CoroutineScope
|
2022-07-16 19:22:22 +03:00
|
|
|
import kotlinx.coroutines.Deferred
|
2022-07-10 22:37:07 +03:00
|
|
|
import kotlin.math.floor
|
|
|
|
|
|
|
|
data class TileId(
|
|
|
|
val zoom: Int,
|
|
|
|
val i: Int,
|
|
|
|
val j: Int,
|
|
|
|
)
|
|
|
|
|
|
|
|
data class MapTile(
|
|
|
|
val id: TileId,
|
|
|
|
val image: ImageBitmap,
|
|
|
|
)
|
|
|
|
|
|
|
|
interface MapTileProvider {
|
2022-07-16 19:22:22 +03:00
|
|
|
fun CoroutineScope.loadTileAsync(tileId: TileId): Deferred<MapTile>
|
2022-07-10 22:37:07 +03:00
|
|
|
|
2022-07-11 20:29:07 +03:00
|
|
|
val tileSize: Int get() = DEFAULT_TILE_SIZE
|
|
|
|
|
|
|
|
fun toIndex(d: Double): Int = floor(d / tileSize).toInt()
|
|
|
|
|
|
|
|
fun toCoordinate(i: Int): Double = (i * tileSize).toDouble()
|
|
|
|
|
|
|
|
companion object {
|
2022-07-10 22:37:07 +03:00
|
|
|
const val DEFAULT_TILE_SIZE = 256
|
|
|
|
}
|
2022-07-14 20:53:41 +03:00
|
|
|
}
|