Skip to content

Basic map view - #1

Merged
garado merged 15 commits into
devfrom
feat/basic-map-view
Aug 4, 2026
Merged

Basic map view#1
garado merged 15 commits into
devfrom
feat/basic-map-view

Conversation

@garado

@garado garado commented Aug 4, 2026

Copy link
Copy Markdown
Owner

Basic raster tile map implementation.

  • doesn't perform like absolute shit
  • local map tile cache (sqlite)

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a basic raster-tile map tab to the tool UI, including tile fetching and a persistent SQLite/Room-backed tile cache.

Changes:

  • Introduces TransitMapView Compose UI with pan/zoom and tile rendering.
  • Adds MapTileClient to fetch Carto raster tiles with in-memory + Room disk caching and eviction.
  • Wires the map tab into HomeScreen and adds Ktor/Room dependencies.

Reviewed changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
tool/src/main/kotlin/dev/garado/transit/map/TransitMapView.kt Compose map UI: gesture handling, debounced refetch, tile drawing.
tool/src/main/kotlin/dev/garado/transit/map/MapTileClient.kt Tile fetcher and cache orchestration (memory + Room disk cache).
tool/src/main/kotlin/dev/garado/transit/map/MapUtils.kt Web Mercator helper utilities and projection math.
tool/src/main/kotlin/dev/garado/transit/map/TileEntity.kt Room entity for cached tiles.
tool/src/main/kotlin/dev/garado/transit/map/TileDao.kt Room DAO for cache read/write, touch, eviction queries.
tool/src/main/kotlin/dev/garado/transit/map/TileCacheDatabase.kt Room database definition for tile cache.
tool/src/main/kotlin/dev/garado/transit/HomeScreen.kt Creates the tile cache DB and replaces the placeholder Map tab with the real map view.
tool/build.gradle.kts Adds Ktor client + Room runtime/ktx dependencies (plus KSP compiler already present).
Suppressed comments (2)

tool/src/main/kotlin/dev/garado/transit/map/TransitMapView.kt:101

  • centerLat/centerLon are unbounded during pan; large values can push latitude outside Web Mercator limits, which makes lonLatToTileFraction() produce NaN/Inf and can break tile math/rendering. Clamp latitude to ±85.0511 and wrap longitude to [-180, 180) when updating the center.
                        val metersPerPx = metersPerPixel(centerLat, zoom.toDouble())
                        centerLon -= (pan.x * metersPerPx) / (METERS_PER_DEGREE_LAT * cos(Math.toRadians(centerLat)))
                        centerLat += (pan.y * metersPerPx) / METERS_PER_DEGREE_LAT
                        if (gestureZoom != 1f) {
                            zoom = (zoom + (ln(gestureZoom.toDouble()) / ln(2.0)).toFloat()).coerceIn(MIN_ZOOM, MAX_ZOOM)

tool/src/main/kotlin/dev/garado/transit/map/MapTileClient.kt:120

  • fetchTilesAround launches one coroutine per tile with no concurrency limit. On larger screens this can create a burst of parallel network+DB work (and corresponding memory pressure). Consider bounding concurrent fetches (e.g., with a semaphore); keep onTileReady on the caller context to avoid mutating Compose state from a background thread.
        val tiles = tileCoords
            .map { (tileX, tileY) ->
                async {
                    fetchTile(tileX, tileY, zoom, darkMode)
                        ?.let { FetchedTile(tileX, tileY, it) }

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +115 to +117
val tileCacheDatabase = remember {
lightContext.buildDatabase(TileCacheDatabase::class.java, "tile_cache.db")
}
Comment thread tool/src/main/kotlin/dev/garado/transit/map/TransitMapView.kt
Comment thread tool/src/main/kotlin/dev/garado/transit/map/MapTileClient.kt
Comment on lines +3 to +10
import androidx.room.ColumnInfo
import androidx.room.Entity
import androidx.room.PrimaryKey

/** One cached raster tile, keyed by "style/z/x/y" */
@Entity(tableName = "tiles")
internal data class TileEntity(
@PrimaryKey val key: String,
@garado
garado merged commit 14f8756 into dev Aug 4, 2026
1 check passed
@garado
garado deleted the feat/basic-map-view branch August 4, 2026 04:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants