Modern Apps git

← Modern-Apps.git

maps: upgrade search selections to masked admin labels

Commit
a852a5b49493c8a2581ca5e55f7b9f10f2d578e8
Author
Vayun Mathur <[email protected]>
When
2026-11-08 02:27 UTC (28 days ago)
Parents
77372be
Tapping a rendered place label resolves to an admin feature with a
region mask, but search results selected a bare GenericPlace, so no
mask ever drew for them and the camera never flew there.

Search-result taps now go through selectAndFocus (the deep-link path),
and after the flight lands the selection upgrades to the same-named
rendered admin label carrying a non-null region mask. The upgrade is
guarded by selection identity, queries post-flight, and never replaces
a POI with its containing city.

Verified: :maps:testDevUnitTest green; effect ordering follows from
CameraState.animateTo being suspend and queryRenderedLabels null-safe.

Diff

maps/src/main/java/com/vayunmathur/maps/ui/MapSearchActions.kt
diff --git a/maps/src/main/java/com/vayunmathur/maps/ui/MapSearchActions.kt b/maps/src/main/java/com/vayunmathur/maps/ui/MapSearchActions.ktindex ffed873511..02c5b49dfd 100644--- a/maps/src/main/java/com/vayunmathur/maps/ui/MapSearchActions.kt+++ b/maps/src/main/java/com/vayunmathur/maps/ui/MapSearchActions.kt@@ -54,7 +54,12 @@ internal fun rememberSearchActions(                             ),                         )                     } else {-                        viewModel.set(feature)+                        // Focus as well as select: without the camera move a+                        // distant result opened its card over a map still+                        // showing somewhere else (and any region mask with+                        // it off-screen). selectAndFocus is the same path+                        // deep links use.+                        viewModel.selectAndFocus(feature)                         onCloseSearch()                     }                 }
maps/src/main/java/com/vayunmathur/maps/ui/MapSheetEffects.kt
diff --git a/maps/src/main/java/com/vayunmathur/maps/ui/MapSheetEffects.kt b/maps/src/main/java/com/vayunmathur/maps/ui/MapSheetEffects.ktindex ef4600b685..f67fca456d 100644--- a/maps/src/main/java/com/vayunmathur/maps/ui/MapSheetEffects.kt+++ b/maps/src/main/java/com/vayunmathur/maps/ui/MapSheetEffects.kt@@ -103,6 +103,42 @@ internal fun MapSheetEffects(         )         if (!wide) sheetState?.partialExpand()         viewModel.consumeFocus()+        // Search/deep-link selections are GenericPlaces, which carry no+        // boundary link, so they could never show the region mask. Now the+        // camera is on the place, upgrade the selection to the rendered+        // admin label of the same name at this spot when one is linked —+        // the mask and admin card follow from the selection as they do+        // for a tapped label. No name match, no upgrade.+        val place = viewModel.selectedFeature.value as? SpecificFeature.GenericPlace+            ?: return@LaunchedEffect+        val projection = camera.projection ?: return@LaunchedEffect+        val centre = runCatching {+            projection.screenLocationFromPosition(request.position)+        }.getOrNull() ?: return@LaunchedEffect+        val slop = com.vayunmathur.maps.ui.theme.MapChromeMetrics.hitSlop+        val candidates = projection.queryRenderedLabels(+            androidx.compose.ui.unit.DpRect(+                centre.x - slop, centre.y - slop, centre.x + slop, centre.y + slop,+            ),+            com.vayunmathur.maps.ui.map.MapFeaturePicker.NATIVE_LABEL_LAYER_IDS,+        ).mapNotNull {+            with(com.vayunmathur.maps.ui.map.MapFeaturePicker.Companion) { it.toFeature1() }+        }+        // (toFeature1 is a companion extension; the with() scopes it.)+        if (candidates.isEmpty()) return@LaunchedEffect+        val parsed = candidates.mapNotNull { raw ->+            runCatching {+                kotlinx.coroutines.withContext(kotlinx.coroutines.Dispatchers.IO) {+                    com.vayunmathur.maps.data.parse(raw)+                }+            }.getOrNull()+        }+        val upgrade = com.vayunmathur.maps.ui.map.adminUpgradeFor(place, parsed)+        // The selection may have moved on while parsing; only upgrade the+        // exact selection this focus was for.+        if (upgrade != null && viewModel.selectedFeature.value === place) {+            viewModel.set(upgrade)+        }     }      // While navigating the in-screen overlay is the primary UI, so the sheet stays down.
maps/src/main/java/com/vayunmathur/maps/ui/map/MapSurfaceHelpers.kt
diff --git a/maps/src/main/java/com/vayunmathur/maps/ui/map/MapSurfaceHelpers.kt b/maps/src/main/java/com/vayunmathur/maps/ui/map/MapSurfaceHelpers.ktindex f89d379360..3ca800ee7e 100644--- a/maps/src/main/java/com/vayunmathur/maps/ui/map/MapSurfaceHelpers.kt+++ b/maps/src/main/java/com/vayunmathur/maps/ui/map/MapSurfaceHelpers.kt@@ -315,3 +315,34 @@ internal fun regionMaskFor(         selectedFeature.regionId.takeIf { it != 0L && selectedFeature.position != null }     else -> null }++/**+ * The admin-region selection that should replace a focused [place] because+ * a rendered admin label at its position names the same place, or null.+ *+ * Search (and deep links) can only build a [SpecificFeature.GenericPlace]:+ * the offline POI index carries no boundary link, so a region picked from+ * search could never mask. Once the camera has flown to the place, the+ * rendered labels at that spot do carry the baked `regionId` — upgrading+ * the selection to the matching admin label is what wires the mask (and+ * the admin card) into the search path. Name equality (normalised, see+ * [PoiSearch]) is required so a POI inside a city is never silently+ * replaced by the city itself.+ */+internal fun adminUpgradeFor(+    place: com.vayunmathur.maps.data.SpecificFeature.GenericPlace,+    candidates: List<com.vayunmathur.maps.data.SpecificFeature>,+): com.vayunmathur.maps.data.SpecificFeature? {+    val wanted = com.vayunmathur.maps.util.PoiSearch.normalize(place.name)+    if (wanted.isEmpty()) return null+    return candidates.firstOrNull { candidate ->+        val name = when (candidate) {+            is com.vayunmathur.maps.data.SpecificFeature.Admin0Label -> candidate.name+            is com.vayunmathur.maps.data.SpecificFeature.Admin1Label -> candidate.name+            is com.vayunmathur.maps.data.SpecificFeature.Admin2Label -> candidate.name+            else -> return@firstOrNull false+        }+        com.vayunmathur.maps.util.PoiSearch.normalize(name) == wanted &&+            regionMaskFor(candidate) != null+    }+}