p-lr / MapCompose

A fast, memory efficient Jetpack Compose library to display tiled maps, with support for markers, paths, and rotation.
Apache License 2.0
202 stars 18 forks source link

Support for tap regions #118

Open mburns-acom opened 2 weeks ago

mburns-acom commented 2 weeks ago

Hello, First we are using com.qozix.tileview.TileView, but want to move to a newer library to mitigate the risk of using an older library that is not supported. Since we are using Compose heavily this library caught my eye. My Question: do you think this library would be able to extended to support a tap listener when a tap occurs in a rectangle (and the rectangle may cross tiles)? In a map scenario, image that you have metadata about the map and that you want to display a bottomsheet that changes the info displayed as the user taps on areas of the image. For example they tap near a city name and info about the city is displayed. The tap region would not be visible (no marker, callout, or path). It would virtual data associated with the image. I guess I could implement MapUI.content. Yes?

p-lr commented 2 weeks ago

The library can be extended to support regions. Since regions are basically closed paths which may be filled or not, stroked or not, and for which tap evens are handled inside the geometries (not on the paths). Recently, a user requested to add such tap listeners on paths (in other words, treat them as regions). I postponed this because I believe the library should have first class support for regions.

In the meantime, you could use the onTap api:

/**
 * Registers a tap callback for tap gestures. The callback is invoked with the relative coordinates
 * of the tapped point on the map.
 * Note: the tap gesture is detected only after the [ViewConfiguration.doubleTapMinTimeMillis] has
 * passed, because the layout's gesture detector also detects double-tap gestures.
 */
fun MapState.onTap(tapCb: (x: Double, y: Double) -> Unit) {
    this.tapCb = tapCb
}

Basically, every time the user makes a tap on the map, you know the relative coordiantes of the tap. Since you have the data of your regions (including their geometries), you can check whether the tap is inside your regions or not. This is more code on your side, but this would be an alternative before the library introduces support for regions.

mburns-acom commented 2 weeks ago

Thank you for a quick response. Have a great weekend.