Android Mapview: Control ordering of multiple types of OverlayItems?

只谈情不闲聊 提交于 2019-12-24 08:52:37

问题


I have searched for a while on this problem but have come up trumps.

I have a simple mapview that makes use of custom overlay items on a ManagedOverlay, let's call them redOverlayItem and blueOverlayItem. All the ManagedOverlay does is query my database for a set of locations of varying types and then place them on a map asynchronously.

My managed overlay works fine, however I can't seem to be able to control the "z" ordering. For instance, sometimes I have redOverlayItem 's covering blueOverlayItem 's and vice versa, where I really just want redOverlayItem 's to be on top.

I've exhausted my ideas on how to fix this. How can I control ordering of multiple types of overlay items?


回答1:


Alright guys, I figured it out.

In your Overlay, you need to override getIndexToDraw

//Overriding to return add order rather than latitude order.
protected int getIndexToDraw(int drawingOrder) {
    return drawingOrder;
}

Rather than call super.getIndexToDraw(int), which returns items ordered by latitude value, all I'm doing now is returning the order in which they are added. Then all I do for my array of overlays is sort them accordingly (I'm using Rob Carmick's BeanComparator, but you could use any sorting function really)

BeanComparator bc = new BeanComparator(CustomOverlayItem.class, "getIsRed");
Collections.sort(overlayItemsArray, bc);


来源:https://stackoverflow.com/questions/11182343/android-mapview-control-ordering-of-multiple-types-of-overlayitems

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!