moagrius / TileView

TileView is a subclass of android.view.ViewGroup that asynchronously displays, pans and zooms tile-based images. Plugins are available for features like markers, hotspots, and path drawing.
MIT License
1.46k stars 337 forks source link

Tapping markers doesn't always send event to listener #8

Closed klattimer closed 11 years ago

klattimer commented 11 years ago

If I zoom my map and tap on the markers which are on screen after the zoom has finished I'm able to tap the markers and get an expected response. However if I scroll without zooming, the markers which were not on screen after the zoom do not respond to events. These markers are on screen so therefore should be tappable.

However I am using the onScrollChanged event to change which markers are added/removed to/from the map (we compute which markers overlap and group those together into one marker so the user is always able to tap the markers).

klattimer commented 11 years ago

I've discovered a bug in the tileview which is related (but possibly not the cause of) the following issue.

On this line https://github.com/moagrius/TileView/blob/master/src/com/qozix/tileview/TileView.java#L459

you'll see that the tileview calls up to markerManager.removeView when it should be calling up to markerManager.removeMarker - by removing the view the markerManager's internal markerMap is never updated with the markers which are being removed from the view.

klattimer commented 11 years ago

Fixing the above bug fixes only half of the problem I'm having, the second part of the problem is that the view rect is not correctly set for the view by the time the marker is tapped, I've created a really horrific hack which works for now but isn't ideal. I'm not entirely certain why the call to onLayout isn't updating the rect correctly but I will keep digging until I find the right way to resolve this.

moagrius commented 11 years ago

Very good to know (and good catch by you) to find the removeView/marker mistake - I'll correct that right away.

For the second issue, you might try removing the onChanged test - that was a late add and should work in theory but I really didn't test it explicitly - I assumed the changed boolean params is being correctly passed by the system.

Also, you are free to use standard View listeners (e.g., View.OnClickListener) rather than the MarkerEventListener interface - I'm not sure if that's appropriate for your app, but it's certainly a more familiar set of functionality.

moagrius commented 11 years ago

Fixed and committed.