From 75d162301bce661010b95f31f081a0b19cda1b0e Mon Sep 17 00:00:00 2001 From: atsunatsu Date: Mon, 7 Sep 2026 06:28:58 +0800 Subject: [PATCH] fix: meridians vanish at low zoom (osmdroid clips Mercator X; normalize longitude to view center); hide satellite layer and bottom info card in grid mode --- .../feature/map/MaidenheadGridOverlay.kt | 21 +++++++++++++------ .../look4sat/feature/map/MapScreen.kt | 4 +++- gradle/libs.versions.toml | 4 ++-- 3 files changed, 20 insertions(+), 9 deletions(-) diff --git a/feature/map/src/main/java/com/rtbishop/look4sat/feature/map/MaidenheadGridOverlay.kt b/feature/map/src/main/java/com/rtbishop/look4sat/feature/map/MaidenheadGridOverlay.kt index 2d2dd785..89f05070 100644 --- a/feature/map/src/main/java/com/rtbishop/look4sat/feature/map/MaidenheadGridOverlay.kt +++ b/feature/map/src/main/java/com/rtbishop/look4sat/feature/map/MaidenheadGridOverlay.kt @@ -84,6 +84,7 @@ class MaidenheadGridOverlay : Overlay() { // crosses the antimeridian; index arithmetic still works (PMxx at 360° == same grid) val firstCol = floor(leftLon / cellLon).toInt() val lastCol = ceil(rightLon / cellLon).toInt() + val centerLon = (leftLon + rightLon) / 2.0 // Worked-grid highlight fills (only meaningful at sub-square zoom) if (workedGrids.isNotEmpty() && zoom >= GRID_ZOOM_SUB) { @@ -97,8 +98,8 @@ class MaidenheadGridOverlay : Overlay() { if (yTop == null || yBottom == null) continue for (col in firstCol..lastCol) { val lon = col * cellLon - val xLeft = projectionToX(projection, lon) ?: continue - val xRight = projectionToX(projection, lon + cellLon) ?: continue + val xLeft = projectionToX(projection, lon, centerLon) ?: continue + val xRight = projectionToX(projection, lon + cellLon, centerLon) ?: continue if (xRight < 0f || xLeft > canvas.width) continue if (cellLabel(lat, lon, zoom) in workedGrids) { canvas.drawRect(xLeft, yTop, xRight, yBottom, workedPaint) @@ -110,7 +111,7 @@ class MaidenheadGridOverlay : Overlay() { // Vertical lines (meridians) for (col in firstCol..lastCol) { val lon = col * cellLon - val x = projectionToX(projection, lon) + val x = projectionToX(projection, lon, centerLon) if (x == null) continue canvas.drawLine(x, 0f, x, canvas.height.toFloat(), linePaint) } @@ -149,7 +150,7 @@ class MaidenheadGridOverlay : Overlay() { if (y < -labelPaint.textSize || y > canvas.height) continue for (col in firstCol..lastCol) { val lon = col * cellLon - val x = projectionToX(projection, lon) ?: continue + val x = projectionToX(projection, lon, centerLon) ?: continue if (x < -200f || x > canvas.width) continue val label = cellLabel(lat, lon, zoom) canvas.drawText(label, x + labelOffset, y + labelPaint.textSize + labelOffset, labelPaint) @@ -158,8 +159,16 @@ class MaidenheadGridOverlay : Overlay() { } /** X pixel for a longitude (meridians are vertical in Web Mercator). */ - private fun projectionToX(projection: Projection, lon: Double): Float? { - val geo = org.osmdroid.util.GeoPoint(0.0, lon) + private fun projectionToX(projection: Projection, lon: Double, centerLon: Double): Float? { + // osmdroid clips Mercator X to [0, mapSize], which destroys the projection of + // longitudes outside the [0, 360) window of the current view (visible at low + // zoom where the whole world is narrower than the viewport). Normalizing the + // longitude to the equivalent value closest to the view center keeps every + // meridian's X near the center, safely inside the clip window. + var normalized = lon + while (normalized < centerLon - 180.0) normalized += 360.0 + while (normalized > centerLon + 180.0) normalized -= 360.0 + val geo = org.osmdroid.util.GeoPoint(0.0, normalized) val p = projection.toPixels(geo, null) return if (p.x in -MAX_OVERSHOOT_PX..MAX_OVERSHOOT_PX + 4096) p.x.toFloat() else null } diff --git a/feature/map/src/main/java/com/rtbishop/look4sat/feature/map/MapScreen.kt b/feature/map/src/main/java/com/rtbishop/look4sat/feature/map/MapScreen.kt index 518acbef..0fb51824 100644 --- a/feature/map/src/main/java/com/rtbishop/look4sat/feature/map/MapScreen.kt +++ b/feature/map/src/main/java/com/rtbishop/look4sat/feature/map/MapScreen.kt @@ -173,7 +173,9 @@ private fun MapScreen(uiState: MapState, onAction: (MapAction) -> Unit, mapView: view.invalidate() } uiState.mapData?.let { mapData -> - if (isVertical) MapDataCard(mapData) else MapDataCards(mapData) + if (!uiState.isGridMode) { + if (isVertical) MapDataCard(mapData) else MapDataCards(mapData) + } } } } diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index cbc000aa..54cdb00b 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -1,8 +1,8 @@ [versions] #noinspection UnusedVersionCatalogEntry -appVersionCode = "453" +appVersionCode = "454" #noinspection UnusedVersionCatalogEntry -appVersionName = "4.4.6-ba7opf.9.1" +appVersionName = "4.4.6-ba7opf.9.2" #noinspection UnusedVersionCatalogEntry compileSdk = "37" #noinspection UnusedVersionCatalogEntry