Rallista / maplibre-compose-playground

Composable MapLibre for Android Kotlin.
Mozilla Public License 2.0
6 stars 3 forks source link

Feature Tap Gesture #51

Open ahmedre opened 2 weeks ago

ahmedre commented 2 weeks ago

Hi, Thanks for building this! Have been looking at this library to consider using it, and wanted to ask a question about this -

"MapView detected features at location. Consider using feature tap gesture instead if using have runtime features."

Does this function exist today?

My use case is that the server side gives us some data on the maps, and, today, on click, we show something by extracting information about them from the underlying features.

If not, would you consider adding a matching features list parameter to the MapGestureContext?

Thanks!

Archdoog commented 2 days ago

Those features do partially exist. But there's room for improvement. E.g. Symbol.kt#L40. This of course only works for features you add through the library dynamically.

If you want feature id's from a map style under a gesture. A PR where we including the queried features inside the MapGestureContext that's returned in the gesture closure could work. That would allow access to the features ids that existed under the gesture which you could then do whatever with.

Something like:

onTapGestureCallback?.let {
    this.addOnMapClickListener { point ->
      val screenLocation = projection.toScreenLocation(point)
      val features = queryRenderedFeatures(screenLocation)

      onTapGestureCallback.invoke(
          MapGestureContext(
              screenLocation, MapGestureType.TAP, LatLng(point.latitude, point.longitude), features))
      true
    }
  }

Where instead of just logging features, we pass them through the MapGestureContext to the caller.