Search code examples
androidgoogle-mapsandroid-mapviewitemizedoverlay

using OnTap(int i) with multiple layers of ItemizedOverlay


I had to show multiple (around 600, all clickable to show some info about them) overlay items on mapview. For performance issues, i thought it would be wise to group them into different ItemizedOverlay classes because every group will show different kind of informations about them. (Spesifically items are Airports, VORs, NDBs and such things about aviation).

My problem is, if i seperate them into classes and show them, performance is super. Map flows fluently. But when i add second layer on top of first, items on the first layer becomes unclickable.

When i read a lot, and debugged using Log.i method, i realised that every layer gets clicked but only OnTap(Geopoint point, MapView mapview) method gets called. Calling super.onTap(point, mapview) didn't work. I need onTap(int index) method to identify the marker. (I have both methods in my classes (after i read lots of examples)).

So, what should i do? Is there any method to solve my problem? I dont want to go into heavy approaches like comparing clicked coordinates to all overlay items coordinates to find anything close.

Thanks in advance.


Solution

  • The way onTop (and any other touch event works on android) is that it will ping any and all objects that are at the coordinates until one of the onTaps (or any other touch event) returns true. In this case, your onTap(Geopoint point, MapView mapview) method is returning true. This consumes that touch event and does not let it pass on to any other onTap events. If you make the onTap event return false, the other onTap events will get pinged. I hope this helps.