2022-07-23 10:58:16 +03:00
|
|
|
package center.sciprog.maps.compose
|
2022-07-10 22:37:07 +03:00
|
|
|
|
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-09-20 13:57:41 +03:00
|
|
|
import org.jetbrains.skia.Image
|
2022-07-10 22:37:07 +03:00
|
|
|
import kotlin.math.floor
|
|
|
|
|
2022-07-23 13:49:47 +03:00
|
|
|
public data class TileId(
|
2022-07-10 22:37:07 +03:00
|
|
|
val zoom: Int,
|
|
|
|
val i: Int,
|
|
|
|
val j: Int,
|
|
|
|
)
|
|
|
|
|
2022-07-23 13:49:47 +03:00
|
|
|
public data class MapTile(
|
2022-07-10 22:37:07 +03:00
|
|
|
val id: TileId,
|
2022-09-20 13:57:41 +03:00
|
|
|
val image: Image,
|
2022-07-10 22:37:07 +03:00
|
|
|
)
|
|
|
|
|
2022-07-23 13:49:47 +03:00
|
|
|
public interface MapTileProvider {
|
|
|
|
public fun CoroutineScope.loadTileAsync(tileId: TileId): Deferred<MapTile>
|
2022-07-10 22:37:07 +03:00
|
|
|
|
2022-07-23 13:49:47 +03:00
|
|
|
public val tileSize: Int get() = DEFAULT_TILE_SIZE
|
2022-07-11 20:29:07 +03:00
|
|
|
|
2022-07-23 13:49:47 +03:00
|
|
|
public fun toIndex(d: Double): Int = floor(d / tileSize).toInt()
|
2022-07-11 20:29:07 +03:00
|
|
|
|
2022-07-23 13:49:47 +03:00
|
|
|
public fun toCoordinate(i: Int): Double = (i * tileSize).toDouble()
|
2022-07-11 20:29:07 +03:00
|
|
|
|
2022-07-23 13:49:47 +03:00
|
|
|
public companion object {
|
|
|
|
public const val DEFAULT_TILE_SIZE: Int = 256
|
2022-07-10 22:37:07 +03:00
|
|
|
}
|
2022-07-14 20:53:41 +03:00
|
|
|
}
|