maps: category chips filter on-map ma_pois by POI type (not text search) + widen POI tap hit-box (~22dp) so near-glyph taps select the place
- Commit
c0e8982d68df48566acca43d5bec61c6b512dc17- Author
- vayun-mathur <[email protected]>
- When
- 2026-08-18 16:05 UTC (3 months ago)
- Parents
f668759
Diff
maps/src/main/java/com/vayunmathur/maps/ui/CategoryChips.kt
diff --git a/maps/src/main/java/com/vayunmathur/maps/ui/CategoryChips.kt b/maps/src/main/java/com/vayunmathur/maps/ui/CategoryChips.ktindex 6c5b94d00a..dc7345a0eb 100644--- a/maps/src/main/java/com/vayunmathur/maps/ui/CategoryChips.kt+++ b/maps/src/main/java/com/vayunmathur/maps/ui/CategoryChips.kt@@ -8,41 +8,53 @@ import androidx.compose.runtime.Composable import androidx.compose.ui.Modifier import androidx.compose.ui.res.stringResource import androidx.compose.ui.unit.dp-import com.vayunmathur.library.ui.AssistChip+import com.vayunmathur.library.ui.FilterChip import com.vayunmathur.library.ui.Text import com.vayunmathur.maps.R+import com.vayunmathur.maps.util.PoiCategories -/** One quick-search category chip: a display label and the query it runs. */-data class MapCategory(val labelRes: Int, val query: String)+/**+ * One quick category: a display label, the Google search [query] it runs on the+ * search page, and the set of OSM POI [types] ([PoiCategories]) it filters the+ * on-map `ma_pois` layer down to on the browse screen.+ */+data class MapCategory(val labelRes: Int, val query: String, val types: Set<Int>) /** * Shared quick-category definitions, reused by both the browse map screen and- * the search page so the two stay in lock-step (Vela's `CategoryChips`). Each- * chip runs the same Google search query wired up in P3.+ * the search page so the two stay in lock-step (Vela's `CategoryChips`). On the+ * browse map a chip FILTERS the native `ma_pois` layer to its [MapCategory.types];+ * on the search page it runs the [MapCategory.query] Google search (P3). */ val MAP_CATEGORIES: List<MapCategory> = listOf(- MapCategory(R.string.search_category_restaurants, "restaurants"),- MapCategory(R.string.search_category_coffee, "coffee"),- MapCategory(R.string.search_category_gas, "gas station"),- MapCategory(R.string.search_category_groceries, "groceries"),- MapCategory(R.string.search_category_hotels, "hotels"),- MapCategory(R.string.search_category_atms, "atm"),+ MapCategory(R.string.search_category_restaurants, "restaurants", setOf(0, 2)),+ MapCategory(R.string.search_category_coffee, "coffee", setOf(1)),+ MapCategory(R.string.search_category_gas, "gas station", setOf(6)),+ MapCategory(R.string.search_category_groceries, "groceries", setOf(5)),+ MapCategory(R.string.search_category_hotels, "hotels", setOf(8)),+ MapCategory(R.string.search_category_atms, "atm", setOf(9)), ) /** * Horizontally-scrolling row of quick category chips. [onCategory] is invoked- * with the chip's Google search query โ on browse this opens the search page- * pre-filled with that query; on the search page it runs the query in place.+ * with the tapped [MapCategory] โ on browse this toggles the on-map POI filter,+ * on the search page it runs the category's Google query. [selected] is the+ * currently-active category (shown highlighted), or null when none is active. */ @Composable-fun CategoryChips(onCategory: (String) -> Unit, modifier: Modifier = Modifier) {+fun CategoryChips(+ onCategory: (MapCategory) -> Unit,+ modifier: Modifier = Modifier,+ selected: MapCategory? = null,+) { Row( modifier = modifier.horizontalScroll(rememberScrollState()), horizontalArrangement = Arrangement.spacedBy(8.dp), ) { MAP_CATEGORIES.forEach { category ->- AssistChip(- onClick = { onCategory(category.query) },+ FilterChip(+ selected = category == selected,+ onClick = { onCategory(category) }, label = { Text(stringResource(category.labelRes)) }, ) }
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 256464bfdc..1da2dde5d3 100644--- a/maps/src/main/java/com/vayunmathur/maps/ui/MaPoisLayer.kt+++ b/maps/src/main/java/com/vayunmathur/maps/ui/MaPoisLayer.kt@@ -9,8 +9,10 @@ import com.vayunmathur.maps.data.SpecificFeature import com.vayunmathur.maps.data.string import com.vayunmathur.maps.util.MapTileCache import com.vayunmathur.maps.util.PoiCategories+import org.maplibre.compose.expressions.dsl.any import org.maplibre.compose.expressions.dsl.case import org.maplibre.compose.expressions.dsl.const+import org.maplibre.compose.expressions.dsl.eq import org.maplibre.compose.expressions.dsl.feature import org.maplibre.compose.expressions.dsl.image import org.maplibre.compose.expressions.dsl.interpolate@@ -49,18 +51,29 @@ object MaPoisSource { * on the same PMTiles triggers a directory parse error). The disc icons are * runtime Canvas bitmaps (no sprite/glyph assets needed), so this renders even * while the style's remote glyphs 404; the POI NAME is shown in the sheet on tap.+ *+ * When [filterTypes] is non-null and non-empty the layer is filtered to just+ * those numeric types (the browse category chips, see MapPage); null shows all. */ @Composable @MaplibreComposable-fun MaPoisLayer(source: VectorSource) {+fun MaPoisLayer(source: VectorSource, filterTypes: Set<Int>? = null) { val icons = remember { poiIcons() } + // Category filter (browse chips): show only features whose `type` is in the+ // selected set, or everything when no category is active.+ val typeFilter = filterTypes+ ?.takeIf { it.isNotEmpty() }+ ?.let { types -> any(*types.map { feature["type"].cast<IntValue>() eq const(it) }.toTypedArray()) }+ ?: const(true)+ // Category icon, chosen by the numeric `type` (0..49, 255 = other). SymbolLayer( MA_POIS_LAYER_ID, source, sourceLayer = MaPoisSource.SOURCE_LAYER, minZoom = 12f,+ filter = typeFilter, iconImage = switch( feature["type"].cast<IntValue>(), *PoiCategories.ALL_TYPES
maps/src/main/java/com/vayunmathur/maps/ui/MapPage.kt
diff --git a/maps/src/main/java/com/vayunmathur/maps/ui/MapPage.kt b/maps/src/main/java/com/vayunmathur/maps/ui/MapPage.ktindex e076acc4f3..813f1628e1 100644--- a/maps/src/main/java/com/vayunmathur/maps/ui/MapPage.kt+++ b/maps/src/main/java/com/vayunmathur/maps/ui/MapPage.kt@@ -61,6 +61,7 @@ import androidx.compose.ui.graphics.graphicsLayer import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.res.painterResource import androidx.compose.ui.res.stringResource+import androidx.compose.ui.unit.DpRect import androidx.compose.ui.unit.dp import com.vayunmathur.library.R import com.vayunmathur.library.ui.IconClose@@ -155,6 +156,11 @@ fun MapPage(backStack: NavBackStack<Route>, viewModel: SelectedFeatureViewModel, // and pushes updates only while bound. Empty when findfamily is absent. val familyMembers by com.vayunmathur.maps.ipc.rememberFamilyMembers() + // Active browse-category POI filter (P29): when set, the on-map `ma_pois`+ // layer is filtered to this category's OSM types (see MaPoisLayer). null =+ // no filter (all POIs shown). Toggled by the CategoryChips row below.+ var selectedCategory by remember { mutableStateOf<MapCategory?>(null) }+ // TEST: default to San Francisco at z14 so the native ma_pois POIs are // visible on cold start. val camera = rememberCameraState(CameraPosition(target = Position(-122.4194, 37.7749), zoom = 14.0))@@ -472,11 +478,17 @@ fun MapPage(backStack: NavBackStack<Route>, viewModel: SelectedFeatureViewModel, onMapClick = { latLng, offset -> coroutineScope.launch { val projection = camera.projection+ // Give pin taps a tolerance box (~22dp radius)+ // around the touch point so tapping NEAR a small+ // POI glyph still selects it, instead of only+ // registering on a pixel-exact hit.+ val pad = 22.dp+ val hitBox = DpRect(offset.x - pad, offset.y - pad, offset.x + pad, offset.y + pad) // Parking pin (P9): tapping the saved car spot // opens the parking sheet instead of selecting a // place. val parkingHit = projection?.queryRenderedFeatures(- offset,+ hitBox, setOf(PARKING_PIN_LAYER_ID) )?.isNotEmpty() == true if (parkingHit) {@@ -489,7 +501,7 @@ fun MapPage(backStack: NavBackStack<Route>, viewModel: SelectedFeatureViewModel, // place. Only hit-tested while the layer is on. if (transitEnabled) { val stopHit = projection?.queryRenderedFeatures(- offset,+ hitBox, setOf(TRANSIT_STOP_LAYER_ID) )?.firstNotNullOfOrNull { it.toTransitStop() } if (stopHit != null) {@@ -505,19 +517,19 @@ fun MapPage(backStack: NavBackStack<Route>, viewModel: SelectedFeatureViewModel, // the Google rich details and GooglePoiEnrichment // renders. val pinHit = projection?.queryRenderedFeatures(- offset,+ hitBox, setOf(SEARCH_RESULT_LAYER_ID) )?.firstNotNullOfOrNull { it.toSelectedSearchResult() } ?: projection?.queryRenderedFeatures(- offset,+ hitBox, setOf(SAVED_PLACE_LAYER_ID) )?.firstNotNullOfOrNull { it.toSelectedSavedPlace() } ?: projection?.queryRenderedFeatures(- offset,+ hitBox, setOf(FAMILY_LOCATION_LAYER_ID) )?.firstNotNullOfOrNull { it.toSelectedFamilyMember() } ?: projection?.queryRenderedFeatures(- offset,+ hitBox, setOf(MA_POIS_LAYER_ID) )?.firstNotNullOfOrNull { it.toSelectedMaPoi() } if (pinHit != null) {@@ -574,7 +586,7 @@ fun MapPage(backStack: NavBackStack<Route>, viewModel: SelectedFeatureViewModel, ClickResult.Pass } ) {- MyMapLayers(selectedFeature, route?.get(selectedRouteType), json, userPosition, userBearing, navProgress, searchResults, savedPins, parkingSpot, transitStops, familyMembers, trafficEnabled, satelliteEnabled, safetyEnabled, transitEnabled)+ MyMapLayers(selectedFeature, route?.get(selectedRouteType), json, userPosition, userBearing, navProgress, searchResults, savedPins, parkingSpot, transitStops, familyMembers, trafficEnabled, satelliteEnabled, safetyEnabled, transitEnabled, poiFilterTypes = selectedCategory?.types) } } @@ -635,11 +647,16 @@ fun MapPage(backStack: NavBackStack<Route>, viewModel: SelectedFeatureViewModel, } } else { Column(Modifier.padding(16.dp).fillMaxWidth()) {- // Quick category chips (Vela's browse CategoryChips),- // wired to the P3 Google search categories. (Home/Work- // quick-access slots moved to the search page.)+ // Quick category chips (Vela's browse CategoryChips):+ // tapping one FILTERS the on-map POIs to that category's+ // OSM types (toggle off by tapping the active chip) rather+ // than running a text search. (Home/Work quick-access slots+ // moved to the search page.) CategoryChips(- onCategory = { openCategorySearch(it) },+ onCategory = { cat ->+ selectedCategory = if (selectedCategory == cat) null else cat+ },+ selected = selectedCategory, modifier = Modifier.fillMaxWidth(), ) Spacer(Modifier.height(8.dp))
maps/src/main/java/com/vayunmathur/maps/ui/MyMapLayers.kt
diff --git a/maps/src/main/java/com/vayunmathur/maps/ui/MyMapLayers.kt b/maps/src/main/java/com/vayunmathur/maps/ui/MyMapLayers.ktindex 27ddcd9ed5..80396d7650 100644--- a/maps/src/main/java/com/vayunmathur/maps/ui/MyMapLayers.kt+++ b/maps/src/main/java/com/vayunmathur/maps/ui/MyMapLayers.kt@@ -65,6 +65,7 @@ fun MyMapLayers( satelliteEnabled: Boolean = false, safetyEnabled: Boolean = false, transitEnabled: Boolean = false,+ poiFilterTypes: Set<Int>? = null, ) { val context = LocalContext.current @@ -149,8 +150,9 @@ fun MyMapLayers( // avoids the second-source "PMTiles directory" parse error that broke the // original overlay, and it removes the slow per-viewport offline-index // GeoJSON pins path. Google is still hit only on tap for rich details- // (see MapPage.onMapClick -> toSelectedMaPoi).- MaPoisLayer(adminSource)+ // (see MapPage.onMapClick -> toSelectedMaPoi). A non-null [poiFilterTypes]+ // (set by tapping a category chip) filters the layer to those OSM types.+ MaPoisLayer(adminSource, poiFilterTypes) // Saved-place pins (Home / Work / starred list). Tap re-selects the // place โ PlaceSheet (Vela's SavedPin).
maps/src/main/java/com/vayunmathur/maps/ui/SearchPage.kt
diff --git a/maps/src/main/java/com/vayunmathur/maps/ui/SearchPage.kt b/maps/src/main/java/com/vayunmathur/maps/ui/SearchPage.ktindex 5108da6339..3d23cdc57b 100644--- a/maps/src/main/java/com/vayunmathur/maps/ui/SearchPage.kt+++ b/maps/src/main/java/com/vayunmathur/maps/ui/SearchPage.kt@@ -171,7 +171,7 @@ fun SearchScreen(state: SearchUiState, actions: SearchActions) { ) { paddingValues -> Column(modifier = Modifier.padding(paddingValues).fillMaxSize()) { CategoryChips(- onCategory = { actions.setQuery(it) },+ onCategory = { actions.setQuery(it.query) }, modifier = Modifier .fillMaxWidth() .padding(horizontal = 16.dp, vertical = 8.dp),