maps: drop the Wikidata proxy; place data comes from the archive
- Commit
7bafa7b49f6b945c206c308f9b517b4fc4b5bbf4- Author
- Vayun Mathur <[email protected]>
- When
- 2026-11-26 01:08 UTC (10 days ago)
- Parents
f3cf6c1
Deletes maps/data/Wikidata.kt and the /api/wikidata/items network call: SpecificFeature.parse() now builds admin labels purely from archive-supplied kind/name/name:en/regionId, and the iso/wikipedia label fields stay nullable in the serialized model so a future archive can fill them without a model change. Investigation showed practically nothing is lost today: the proxy supplied country/region ISO codes (consumed by no UI or logic) and a Wikipedia URL, but the live label path never carried a wikidata property into parse(), so the Wikipedia button already never appeared. POI sheets were already fully local (poi_attrs: hours, phone, website, address, cuisine, wheelchair, rating). Restoring enrichment properly is a planet-build join (wikidata/wikipedia keys 13/14 in osm_ingest poi_attrs; the existing scripts/maps/wikidesc crate is the natural join point) — not implemented here. Verified: :maps:testDevUnitTest passes; :maps:lint errors are pre-existing DialogAsRoute findings in untouched files, zero in touched files.
Diff
maps/AGENTS.md
diff --git a/maps/AGENTS.md b/maps/AGENTS.mdindex 43c5c3b582..d6df913428 100644--- a/maps/AGENTS.md+++ b/maps/AGENTS.md@@ -175,7 +175,6 @@ _Install: ./install maps (dev by default)._ - com/vayunmathur/maps/domain/SpatialKey.kt - com/vayunmathur/maps/platform/RegionalUnits.kt - com/vayunmathur/maps/domain/ItineraryWording.kt-- com/vayunmathur/maps/data/Wikidata.kt - com/vayunmathur/maps/domain/CameraBounds.kt - com/vayunmathur/maps/platform/ContactLookup.kt - com/vayunmathur/maps/platform/FrameworkLocationManager.kt
maps/src/main/java/com/vayunmathur/maps/data/SpecificFeature.kt
diff --git a/maps/src/main/java/com/vayunmathur/maps/data/SpecificFeature.kt b/maps/src/main/java/com/vayunmathur/maps/data/SpecificFeature.ktindex 69d95541e8..9c2b39466f 100644--- a/maps/src/main/java/com/vayunmathur/maps/data/SpecificFeature.kt+++ b/maps/src/main/java/com/vayunmathur/maps/data/SpecificFeature.kt@@ -3,7 +3,6 @@ package com.vayunmathur.maps.data import com.vayunmathur.library.log.Log import com.vayunmathur.library.map.GeoPoint import com.vayunmathur.maps.data.PoiIndex-import com.vayunmathur.maps.data.Wikidata import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.withContext import kotlinx.serialization.SerialName@@ -21,9 +20,9 @@ sealed interface SpecificFeature { } /**- * A country. [iso] and [wikipedia] are optional because the basemap archive carries neither:- * a picked label supplies a name and a position, and the Wikidata round trip that fills these- * in needs the network. Requiring them meant tapping a country did nothing at all offline.+ * A country. [iso] and [wikipedia] are optional because the basemap archive carries+ * neither: a picked label supplies a name and a position. Both stay null until the+ * planet build bakes them into the archive. * * [regionId] is the baked link: the tagged OSM relation id of the boundary this label * names, stamped at build time (see `region_links`). `0` means unlinked — mask nothing.@@ -152,25 +151,15 @@ fun JsonObject.string(key: String): String? = this[key]?.jsonPrimitive?.content * Resolve a tapped basemap feature into a [SpecificFeature]. * * Amenities are drawn by the renderer and picked there, arriving as `MapClick.poi`, so this- * no longer reads the amenities DB: it only handles the country/region/city admin labels- * (Wikidata-backed). Everything else returns null.+ * only handles the country/region/city admin labels. Everything else returns null.+ *+ * A picked label supplies `kind`, `name`, `name:en` and the baked `regionId` — all from the+ * archive, no network. The ISO code and Wikipedia article the label types carry stay null:+ * the archive does not bake them in yet, and the sheet already renders without them. */ suspend fun parse(feature: Feature1): SpecificFeature? { val properties = feature.properties ?: return null- // The name is the only thing an admin label truly needs. Everything below it is enrichment- // from Wikidata, which the basemap archive does not carry and which needs the network.- //- // Requiring that enrichment is what made tapping a city, state or country do nothing: a- // picked label supplies `kind`, `name` and `name:en` and nothing else, so `wikidata` was- // always absent, every branch returned null, and the tap fell through to reverse-geocode —- // which is online-only and therefore silent offline. Two `runCatching` swallows on the path- // meant it failed without a trace. val name = properties.string("name:en") ?: properties.string("name") ?: return null- // Absent id, or a lookup that fails or times out, leaves the article and ISO code unset- // rather than losing the whole feature.- val wiki = properties.string("wikidata")?.let { id ->- try { Wikidata.get(id) } catch (_: Exception) { null }- } // Where the label sits, kept for search-picked regions and as a fallback anchor: the // mask itself is the baked `regionId` below, not a containment probe. val at = (feature.geometry as? Point)?.coordinates@@ -180,23 +169,16 @@ suspend fun parse(feature: Feature1): SpecificFeature? { Log.dev("RegionDbg", "parse kind=${properties.string("kind")} name=$name regionId=$regionId") return when (properties.string("kind")) { "country" -> SpecificFeature.Admin0Label(- iso = wiki?.getProperty("P297"),- wikipedia = wiki?.getWikipedia(), name = name, position = at, regionId = regionId, ) "region" -> SpecificFeature.Admin1Label(- iso = wiki?.getProperty("P300"),- wikipedia = wiki?.getWikipedia(), name = name, position = at, regionId = regionId, )- // No ISO lookup: a city has no ISO 3166 code, so the Wikidata round trip is only for the- // article URL. "locality" -> SpecificFeature.Admin2Label(- wikipedia = wiki?.getWikipedia(), name = name, position = at, regionId = regionId,
maps/src/main/java/com/vayunmathur/maps/data/Wikidata.kt
diff --git a/maps/src/main/java/com/vayunmathur/maps/data/Wikidata.kt b/maps/src/main/java/com/vayunmathur/maps/data/Wikidata.ktdeleted file mode 100644index 7ad35c8e0b..0000000000--- a/maps/src/main/java/com/vayunmathur/maps/data/Wikidata.kt+++ /dev/null@@ -1,43 +0,0 @@-package com.vayunmathur.maps.data-import com.vayunmathur.library.network.NetworkClient-import kotlinx.serialization.Serializable-import kotlinx.serialization.json.JsonElement-import kotlinx.serialization.json.jsonPrimitive--/** Singleton holding wikidata state and operations. */-object Wikidata {- // Proxied via self-hosted to avoid direct third-party (Wikidata rate-limits, privacy).- // Server forwards to https://www.wikidata.org/w/rest.php/wikibase/v1/entities/items/{id} with 24h cache.- private const val BASE_URL = "https://api.maproj.org/api/wikidata/items"-- suspend fun get(wikidata: String): Wikidata {- return NetworkClient.getJson("$BASE_URL/$wikidata")- }-- /** Immutable value describing wikidata. */- @Serializable- data class Wikidata(- val id: String,- val statements: Map<String, List<Statement>>,- val sitelinks: Map<String, Sitelink>- ) {- fun getProperty(property: String) = statements[property]?.first()?.value?.content?.jsonPrimitive?.content- fun getWikipedia() = sitelinks["enwiki"]?.url-- /** Immutable value describing statement. */- @Serializable- data class Statement(- val id: String,- val value: Value,- ) {- /** Immutable value describing value; carries content. */- @Serializable- data class Value(val content: JsonElement? = null)- }- /** Immutable value describing sitelink. */- @Serializable- data class Sitelink(- val url: String,- )- }-}
maps/src/main/java/com/vayunmathur/maps/platform/SelectedFeatureViewModel.kt
diff --git a/maps/src/main/java/com/vayunmathur/maps/platform/SelectedFeatureViewModel.kt b/maps/src/main/java/com/vayunmathur/maps/platform/SelectedFeatureViewModel.ktindex 4fe4aaaa74..606e5b198e 100644--- a/maps/src/main/java/com/vayunmathur/maps/platform/SelectedFeatureViewModel.kt+++ b/maps/src/main/java/com/vayunmathur/maps/platform/SelectedFeatureViewModel.kt@@ -1,7 +1,6 @@ package com.vayunmathur.maps.platform import com.vayunmathur.maps.data.planWithAlternatives import com.vayunmathur.maps.data.OfflineRouterRoadRoutes-import com.vayunmathur.maps.data.Wikidata import com.vayunmathur.maps.domain.AlternativeRoutes import com.vayunmathur.maps.domain.RouteService import android.app.Application@@ -213,10 +212,9 @@ class SelectedFeatureViewModel(application: Application): AndroidViewModel(appli /** * Resolve the first basemap place label that parses, or null. *- * Lives here rather than in the tap handler because `parse` may make a Wikidata round-trip- * per candidate. The native pick returns placed labels in placement order, so stopping at the- * first success is what keeps a tap from doing every round-trip serially — and doing any of- * them on the caller's thread is what made the gesture handler a hundred lines long.+ * Lives here rather than in the tap handler so label resolution stays off the gesture+ * handler's thread. The native pick returns placed labels in placement order, so stopping+ * at the first success keeps a tap from resolving every candidate. */ suspend fun resolveAdminLabel(candidates: List<Feature1>): SpecificFeature? = withContext(Dispatchers.IO) {
maps/src/main/java/com/vayunmathur/maps/ui/BottomSheetContent.kt
diff --git a/maps/src/main/java/com/vayunmathur/maps/ui/BottomSheetContent.kt b/maps/src/main/java/com/vayunmathur/maps/ui/BottomSheetContent.ktindex ec98ea45d3..c7bf21fd1d 100644--- a/maps/src/main/java/com/vayunmathur/maps/ui/BottomSheetContent.kt+++ b/maps/src/main/java/com/vayunmathur/maps/ui/BottomSheetContent.kt@@ -1,7 +1,6 @@ package com.vayunmathur.maps.ui import com.vayunmathur.maps.platform.PlacePanelState import com.vayunmathur.maps.data.string-import com.vayunmathur.maps.data.Wikidata import com.vayunmathur.maps.platform.rememberPlacePanelState import androidx.compose.foundation.layout.Column@@ -174,8 +173,8 @@ private fun AdminLabelHeader(name: String, wikipedia: String?, modifier: Modifie modifier = Modifier.weight(1f), ) // Only when there is an article to open. The name comes from the basemap and is always- // there; the article is a Wikidata lookup that needs the network, so offline the sheet- // shows the place with no button rather than not opening at all.+ // there; the article link is not baked into the archive yet, so the sheet normally+ // shows the place with no button. if (wikipedia != null) { TextButton(onClick = { goto(context, wikipedia) }) { Text(stringResource(R.string.wikipedia))
maps/src/main/java/com/vayunmathur/maps/ui/map/MapFeaturePicker.kt
diff --git a/maps/src/main/java/com/vayunmathur/maps/ui/map/MapFeaturePicker.kt b/maps/src/main/java/com/vayunmathur/maps/ui/map/MapFeaturePicker.ktindex 5cea15aa66..b6607966db 100644--- a/maps/src/main/java/com/vayunmathur/maps/ui/map/MapFeaturePicker.kt+++ b/maps/src/main/java/com/vayunmathur/maps/ui/map/MapFeaturePicker.kt@@ -1,6 +1,5 @@ package com.vayunmathur.maps.ui.map import com.vayunmathur.maps.data.regionId-import com.vayunmathur.maps.data.Wikidata import com.vayunmathur.library.log.Log import androidx.compose.ui.unit.DpOffset@@ -60,9 +59,8 @@ fun interface FeatureSource { * `return`s. * * Not a composable. [pickPin] suspends because a probe's resolver may do I/O. The admin-label- * branch is the opposite arrangement — it used to make a Wikidata round-trip inside the gesture- * handler, and now belongs to the ViewModel, which is why [ADMIN_LABEL_LAYER_IDS] hits come back- * as raw features for the caller to resolve.+ * branch is the opposite arrangement — label resolution belongs to the ViewModel, which is why+ * [ADMIN_LABEL_LAYER_IDS] hits come back as raw features for the caller to resolve. * * Ambient POIs are **not** probed here. The renderer draws them, so the renderer picks them: * a tap arrives as `MapClick.poi` already resolved against the collision pass that put the icon
maps/src/main/java/com/vayunmathur/maps/ui/map/MapSurface.kt
diff --git a/maps/src/main/java/com/vayunmathur/maps/ui/map/MapSurface.kt b/maps/src/main/java/com/vayunmathur/maps/ui/map/MapSurface.ktindex 5fe835abad..6deed9fd2a 100644--- a/maps/src/main/java/com/vayunmathur/maps/ui/map/MapSurface.kt+++ b/maps/src/main/java/com/vayunmathur/maps/ui/map/MapSurface.kt@@ -5,7 +5,6 @@ import kotlinx.coroutines.withContext import com.vayunmathur.maps.data.PoiCategories import com.vayunmathur.maps.data.OfflineRouterTraffic import com.vayunmathur.maps.data.nearest-import com.vayunmathur.maps.data.Wikidata import com.vayunmathur.maps.platform.SearchResult import androidx.compose.runtime.Composable@@ -287,8 +286,7 @@ fun MapSurface( } // Fall back to the basemap's own place labels from the native pick.- // Resolving one may make a Wikidata round-trip, so the ViewModel owns- // that rather than this handler. `VulkanMapSurface` registers the native+ // The ViewModel owns resolving them rather than this handler. `VulkanMapSurface` registers the native // pick, so this is populated whenever a placed label is under the finger; // when nothing is, it falls through to reverse-geocode exactly like a // blank tap.
maps/src/test/java/com/vayunmathur/maps/data/SpecificFeatureSlice3Test.kt
diff --git a/maps/src/test/java/com/vayunmathur/maps/data/SpecificFeatureSlice3Test.kt b/maps/src/test/java/com/vayunmathur/maps/data/SpecificFeatureSlice3Test.ktindex fd98a967d5..7ae60fbe26 100644--- a/maps/src/test/java/com/vayunmathur/maps/data/SpecificFeatureSlice3Test.kt+++ b/maps/src/test/java/com/vayunmathur/maps/data/SpecificFeatureSlice3Test.kt@@ -14,9 +14,9 @@ import kotlin.test.assertTrue * features to admin labels, and [SpecificFeature] matching covers the * routable types. *- * The Wikidata enrichment is skipped here by omitting the `wikidata`- * property, so no network is touched: the label/region resolution is what- * is pinned, including the unknown-kind null and the missing-name null.+ * Label resolution reads only the archive-supplied properties, so no+ * network is touched: the label/region resolution is what is pinned,+ * including the unknown-kind null and the missing-name null. */ class SpecificFeatureSlice3Test {