Basic map view - #1
Merged
Merged
Conversation
There was a problem hiding this comment.
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
TransitMapViewCompose UI with pan/zoom and tile rendering. - Adds
MapTileClientto fetch Carto raster tiles with in-memory + Room disk caching and eviction. - Wires the map tab into
HomeScreenand 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/centerLonare unbounded during pan; large values can push latitude outside Web Mercator limits, which makeslonLatToTileFraction()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
fetchTilesAroundlaunches 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); keeponTileReadyon 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 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, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Basic raster tile map implementation.