Modern Apps git

← Modern-Apps.git

maps: replace POI letter-discs with real category icons (rasterized Material vectors via library:ui MapsPoiVectors) at ~3x size; add station type 50

Commit
30e4ff592d3672ffe32f32d8b2cae2af1c7c3053
Author
vayun-mathur <[email protected]>
When
2026-08-18 16:46 UTC (3 months ago)
Parents
370d063

Diff

library/ui/src/main/java/com/vayunmathur/library/ui/MapsPoiVectors.kt
diff --git a/library/ui/src/main/java/com/vayunmathur/library/ui/MapsPoiVectors.kt b/library/ui/src/main/java/com/vayunmathur/library/ui/MapsPoiVectors.ktnew file mode 100644index 0000000000..8054571436--- /dev/null+++ b/library/ui/src/main/java/com/vayunmathur/library/ui/MapsPoiVectors.kt@@ -0,0 +1,110 @@+package com.vayunmathur.library.ui++import androidx.compose.material.icons.Icons+import androidx.compose.material.icons.filled.AccountBalance+import androidx.compose.material.icons.filled.Attractions+import androidx.compose.material.icons.filled.BakeryDining+import androidx.compose.material.icons.filled.CardGiftcard+import androidx.compose.material.icons.filled.Chair+import androidx.compose.material.icons.filled.Checkroom+import androidx.compose.material.icons.filled.Church+import androidx.compose.material.icons.filled.ContentCut+import androidx.compose.material.icons.filled.Devices+import androidx.compose.material.icons.filled.Diamond+import androidx.compose.material.icons.filled.DirectionsCar+import androidx.compose.material.icons.filled.EvStation+import androidx.compose.material.icons.filled.FitnessCenter+import androidx.compose.material.icons.filled.Hardware+import androidx.compose.material.icons.filled.Hotel+import androidx.compose.material.icons.filled.LocalBar+import androidx.compose.material.icons.filled.LocalCafe+import androidx.compose.material.icons.filled.LocalFireDepartment+import androidx.compose.material.icons.filled.LocalFlorist+import androidx.compose.material.icons.filled.LocalGasStation+import androidx.compose.material.icons.filled.LocalGroceryStore+import androidx.compose.material.icons.filled.LocalHospital+import androidx.compose.material.icons.filled.LocalLaundryService+import androidx.compose.material.icons.filled.LocalLibrary+import androidx.compose.material.icons.filled.LocalParking+import androidx.compose.material.icons.filled.LocalPharmacy+import androidx.compose.material.icons.filled.LocalPolice+import androidx.compose.material.icons.filled.LocalPostOffice+import androidx.compose.material.icons.filled.MedicalServices+import androidx.compose.material.icons.filled.MenuBook+import androidx.compose.material.icons.filled.Museum+import androidx.compose.material.icons.filled.Park+import androidx.compose.material.icons.filled.Pets+import androidx.compose.material.icons.filled.Place+import androidx.compose.material.icons.filled.Restaurant+import androidx.compose.material.icons.filled.School+import androidx.compose.material.icons.filled.ShoppingBag+import androidx.compose.material.icons.filled.SportsSoccer+import androidx.compose.material.icons.filled.Storefront+import androidx.compose.material.icons.filled.Theaters+import androidx.compose.material.icons.filled.Toys+import androidx.compose.material.icons.filled.Train+import androidx.compose.material.icons.filled.Visibility+import androidx.compose.material.icons.filled.Work+import androidx.compose.ui.graphics.vector.ImageVector++/**+ * Curated Material [ImageVector]s for the map's OSM POI categories, exposed here+ * (the one module allowed to touch `androidx.compose.material.icons`) so the maps+ * app can rasterize them into MapLibre marker bitmaps without importing Material+ * icons directly.+ *+ * [of] maps the numeric POI `type` used by the maps app's `PoiCategories`+ * (0..50, 255 = other) to an icon; keep this in sync with that table (never+ * renumber, only append).+ */+object MapsPoiVectors {+    fun of(type: Int): ImageVector = when (type) {+        0, 2 -> Icons.Filled.Restaurant       // restaurant / fast food+        1 -> Icons.Filled.LocalCafe           // cafe+        3, 46 -> Icons.Filled.LocalBar        // bar / liquor+        4 -> Icons.Filled.ShoppingBag         // shop+        5 -> Icons.Filled.LocalGroceryStore   // grocery+        6 -> Icons.Filled.LocalGasStation     // gas station+        7 -> Icons.Filled.LocalPharmacy       // pharmacy+        8 -> Icons.Filled.Hotel               // hotel+        9 -> Icons.Filled.AccountBalance      // bank+        10 -> Icons.Filled.LocalHospital      // hospital+        11 -> Icons.Filled.School             // school+        12 -> Icons.Filled.Park               // park+        13 -> Icons.Filled.FitnessCenter      // gym+        14 -> Icons.Filled.Church             // place of worship+        15, 40 -> Icons.Filled.Attractions    // attraction / tourist info+        16 -> Icons.Filled.LocalParking       // parking+        17 -> Icons.Filled.Theaters           // cinema+        18 -> Icons.Filled.Theaters           // theatre+        19 -> Icons.Filled.LocalLibrary       // library+        20 -> Icons.Filled.LocalPostOffice    // post office+        21 -> Icons.Filled.LocalPolice        // police+        22 -> Icons.Filled.LocalFireDepartment // fire station+        23 -> Icons.Filled.AccountBalance     // town hall+        24 -> Icons.Filled.Checkroom          // clothing+        25 -> Icons.Filled.Devices            // electronics+        26 -> Icons.Filled.Hardware           // hardware+        27 -> Icons.Filled.ContentCut         // beauty+        28 -> Icons.Filled.DirectionsCar      // car+        29 -> Icons.Filled.BakeryDining       // bakery+        30 -> Icons.Filled.MenuBook           // books+        31 -> Icons.Filled.Chair              // furniture+        32 -> Icons.Filled.SportsSoccer       // sports+        33 -> Icons.Filled.Storefront         // department store+        34, 35 -> Icons.Filled.MedicalServices // dentist / doctor+        36, 45 -> Icons.Filled.Pets           // veterinary / pet+        37 -> Icons.Filled.EvStation          // charging station+        38 -> Icons.Filled.Museum             // museum+        39 -> Icons.Filled.Work               // office+        41 -> Icons.Filled.LocalFlorist       // florist+        42 -> Icons.Filled.Diamond            // jewelry+        43 -> Icons.Filled.Visibility         // optician+        44 -> Icons.Filled.LocalLaundryService // laundry+        47 -> Icons.Filled.Toys               // toys+        48 -> Icons.Filled.CardGiftcard       // gift+        49 -> Icons.Filled.Storefront         // marketplace+        50 -> Icons.Filled.Train              // train / transit station+        else -> Icons.Filled.Place            // other / fallback+    }+}
maps/src/main/java/com/vayunmathur/maps/ui/MaPoisLayer.kt
diff --git a/maps/src/main/java/com/vayunmathur/maps/ui/MaPoisLayer.kt b/maps/src/main/java/com/vayunmathur/maps/ui/MaPoisLayer.ktindex 1da2dde5d3..9298c7d106 100644--- a/maps/src/main/java/com/vayunmathur/maps/ui/MaPoisLayer.kt+++ b/maps/src/main/java/com/vayunmathur/maps/ui/MaPoisLayer.kt@@ -1,9 +1,19 @@ package com.vayunmathur.maps.ui  import androidx.compose.runtime.Composable-import androidx.compose.runtime.remember+import androidx.compose.ui.geometry.Size+import androidx.compose.ui.graphics.Canvas+import androidx.compose.ui.graphics.Color+import androidx.compose.ui.graphics.ColorFilter import androidx.compose.ui.graphics.ImageBitmap-import androidx.compose.ui.graphics.asImageBitmap+import androidx.compose.ui.graphics.drawscope.CanvasDrawScope+import androidx.compose.ui.graphics.drawscope.translate+import androidx.compose.ui.graphics.vector.VectorPainter+import androidx.compose.ui.graphics.vector.rememberVectorPainter+import androidx.compose.ui.platform.LocalDensity+import androidx.compose.ui.unit.Density+import androidx.compose.ui.unit.LayoutDirection+import com.vayunmathur.library.ui.MapsPoiVectors import com.vayunmathur.maps.data.Feature1 import com.vayunmathur.maps.data.SpecificFeature import com.vayunmathur.maps.data.string@@ -58,9 +68,9 @@ object MaPoisSource { @Composable @MaplibreComposable fun MaPoisLayer(source: VectorSource, filterTypes: Set<Int>? = null) {-    val icons = remember { poiIcons() }+    val icons = rememberPoiIcons() -    // Category filter (browse chips): show only features whose `type` is in the+    // Category filter (browse chips):     // selected set, or everything when no category is active.     val typeFilter = filterTypes         ?.takeIf { it.isNotEmpty() }@@ -83,9 +93,9 @@ fun MaPoisLayer(source: VectorSource, filterTypes: Set<Int>? = null) {         ),         iconSize = interpolate(             linear(), zoom(),-            12 to const(0.55f),-            15 to const(0.8f),-            18 to const(1.1f),+            12 to const(0.75f),+            15 to const(1.05f),+            18 to const(1.4f),         ),     ) }@@ -104,31 +114,38 @@ fun Feature1.toSelectedMaPoi(): SpecificFeature? {     return SpecificFeature.GenericPlace(name, null, null, null, Position(pos.longitude, pos.latitude)) } -/** Generate one category disc icon per POI type (Decision D5: Compose/Canvas- *  runtime bitmaps rather than sprite assets). */-private fun poiIcons(): Map<Int, ImageBitmap> =-    PoiCategories.ALL_TYPES.associateWith { t ->-        poiDisc(PoiCategories.colorHex(t), PoiCategories.glyph(t))+/** Build one category disc bitmap per POI type: a white-ringed colour disc with+ *  the category's Material vector icon (from [MapsPoiVectors], the one module+ *  allowed to reference Material icons) rasterized white on top. Rendered ~3x the+ *  old resolution (144px) so the enlarged markers stay crisp. */+@Composable+private fun rememberPoiIcons(): Map<Int, ImageBitmap> {+    val density = LocalDensity.current+    // rememberVectorPainter is @Composable, so build a painter per (stable) type.+    val painters: Map<Int, VectorPainter> = PoiCategories.ALL_TYPES.associateWith { t ->+        rememberVectorPainter(MapsPoiVectors.of(t))+    }+    return remember(density) {+        painters.mapValues { (t, painter) -> poiDisc(PoiCategories.colorHex(t), painter, density) }     }+} -/** A white-ringed colour disc with a centred white glyph. */-private fun poiDisc(colorHex: String, glyph: String): ImageBitmap {-    val size = 64-    val bmp = android.graphics.Bitmap.createBitmap(size, size, android.graphics.Bitmap.Config.ARGB_8888)-    val canvas = android.graphics.Canvas(bmp)-    val paint = android.graphics.Paint(android.graphics.Paint.ANTI_ALIAS_FLAG)-    val cx = size / 2f-    val cy = size / 2f-    paint.color = android.graphics.Color.WHITE-    canvas.drawCircle(cx, cy, size / 2f - 2f, paint)-    paint.color = runCatching { android.graphics.Color.parseColor(colorHex) }-        .getOrDefault(android.graphics.Color.parseColor("#5F6368"))-    canvas.drawCircle(cx, cy, size / 2f - 6f, paint)-    paint.color = android.graphics.Color.WHITE-    paint.textAlign = android.graphics.Paint.Align.CENTER-    paint.textSize = size * 0.46f-    paint.isFakeBoldText = true-    val fm = paint.fontMetrics-    canvas.drawText(glyph, cx, cy - (fm.ascent + fm.descent) / 2f, paint)-    return bmp.asImageBitmap()+private fun poiDisc(colorHex: String, painter: VectorPainter, density: Density): ImageBitmap {+    val sizePx = 144+    val bitmap = ImageBitmap(sizePx, sizePx)+    val canvas = Canvas(bitmap)+    val fill = Color(+        runCatching { android.graphics.Color.parseColor(colorHex) }+            .getOrDefault(android.graphics.Color.parseColor("#5F6368")),+    )+    val full = Size(sizePx.toFloat(), sizePx.toFloat())+    CanvasDrawScope().draw(density, LayoutDirection.Ltr, canvas, full) {+        drawCircle(Color.White, radius = sizePx / 2f - 4f, center = center)+        drawCircle(fill, radius = sizePx / 2f - 11f, center = center)+        val iconSide = sizePx * 0.5f+        translate(left = (sizePx - iconSide) / 2f, top = (sizePx - iconSide) / 2f) {+            with(painter) { draw(Size(iconSide, iconSide), colorFilter = ColorFilter.tint(Color.White)) }+        }+    }+    return bitmap }
maps/src/main/java/com/vayunmathur/maps/util/PoiCategories.kt
diff --git a/maps/src/main/java/com/vayunmathur/maps/util/PoiCategories.kt b/maps/src/main/java/com/vayunmathur/maps/util/PoiCategories.ktindex 8372f2a7a0..d2bb1625b9 100644--- a/maps/src/main/java/com/vayunmathur/maps/util/PoiCategories.kt+++ b/maps/src/main/java/com/vayunmathur/maps/util/PoiCategories.kt@@ -15,7 +15,7 @@ object PoiCategories {     const val TYPE_OTHER: Int = 255      /** Every type number the generator can emit, for building the icon switch. */-    val ALL_TYPES: List<Int> = (0..49).toList() + TYPE_OTHER+    val ALL_TYPES: List<Int> = (0..50).toList() + TYPE_OTHER      /** Human-readable category label (used as the search-result subtitle). */     fun label(type: Int): String = when (type) {@@ -69,6 +69,7 @@ object PoiCategories {         47 -> "Toys"         48 -> "Gift"         49 -> "Marketplace"+        50 -> "Station"         else -> "Place"     } @@ -91,6 +92,7 @@ object PoiCategories {         14 -> "#8D6E63"                     // place of worship         15, 40 -> "#FF6D00"                // attraction / tourist info         16, 20, 21, 22, 23, 39 -> "#5F6368" // civic/parking/office (slate)+        50 -> "#3949AB"                      // transit station (indigo)         17, 18 -> "#AB47BC"                // cinema / theatre         24, 27, 41, 42, 47, 48 -> "#E91E63" // apparel/beauty/florist/jewelry/toys/gift         25, 43 -> "#1A73E8"                // electronics / optician