ITADN

MapLibreMap.queryRenderedFeatures returns a Point object when a MultiPoint feature is clicked

#4237Opentguen 创建于 2026-04-18
android
T
tguencommented
### MapLibre Android Version 13.0.2 ### Android SDK Version 36 ### Device Pixel 7a ### What happened? The OpenMapTiles schema uses MultiPoint features for the housenumber layer, so all addresses in a tile with the same housenumber are points in the same MultiPoint feature. When clicking one of these points, an OnMapClickListener can call MapLibreMap.queryRenderedFeatures which returns a Point within the MultiPoint feature that may have geometry at a different location than the point clicked by the user. ### Steps to reproduce Create an app with the following code: ``` kotlin class MainActivity : AppCompatActivity() { private val maptilerKey = "" private val styleUri = "https://api.maptiler.com/maps/streets-v2/style.json?key=$maptilerKey" private val addrLayer = "Housenumber" private val xy = LatLng(45.51474, -122.68636) private val z = 18.0 override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) MapLibre.getInstance(this) val mv = MapView(this) setContentView(mv) mv.getMapAsync { map -> map.setStyle(Style.Builder().fromUri(styleUri)) map.addOnMapClickListener { latLng -> onClick(map, latLng) true } map.cameraPosition = CameraPosition.Builder().target(xy).zoom(z).build() } } private fun onClick(map: MapLibreMap, latLng: LatLng) { val features: List<Feature> = map.queryRenderedFeatures( map.projection.toScreenLocation(latLng), addrLayer) for (f in features) { if (f.geometry() !is Point) continue val pt = f.geometry() as Point val tapLocation = String.format("%.5f %.5f", latLng.latitude, latLng.longitude) val featLocation = String.format("%.5f %.5f", pt.latitude(), pt.longitude()) AlertDialog.Builder(this) .setMessage("tapped at: $tapLocation\nfeature at: $featLocation") .setPositiveButton("Show") { _, _ -> map.cameraPosition = CameraPosition.Builder() .target(LatLng(pt.latitude(), pt.longitude())).build() } .show() } } } ``` Add your MapTiler key and run it. There will be two addresses visible, 1500 SW 11th Ave and 1500 SW 12th Ave. Clicking either will show a dialog with a button that zooms to the geometry returned by queryRenderedFeatures. Regardless of which of the two addresses is clicked, the map will zoom to the address on 12th Ave. ### Renderer _No response_ ### Relevant log output ```shell ``` ### Additional context _No response_
0 条评论