confusion between overlay, overlayitem and itemizedoverley

痞子三分冷 提交于 2019-12-12 01:33:49

问题


I wanting to create an app which displays a map and on top of this map, the roads and points of interests will be painted as lines and ovals. These lines and ovals will have listeners attached to them so the user can drag them around or delete them.

I am using openstreetmaps with osmdroid however it seems to be exactly the same as Google Maps.

I was thinking of extending the OverlayItem class to represent a point of interest or a road. The Overlay class would be extended and contain an ArrayList of these extended OverlayItems.

The draw method of the Overlay class would be overridden and would paint all of the OverlayItem contained in the arraylist.

This Overlay class is then added to the MapView.

I am not sure if this would work because a lot of tutorials use an ItemizedOverlay. What exactly is this and should I be using it?

Thanks


回答1:


An ItemizedOverlay is a class extending Overlay (as you want to do) and mostly completed (you still need to extend it and fill the specific parts) in order to add a list of Drawables to the map in specified Geopoints (using a list of OverlayItem). It also implements onTap() for the items added.

So bottom line, ItemizedOverlay is a pre-coded class aiming what seems to be your objective.

Limitations

It may not be the best solution for all your overlays ...

Examples where it would be better to use your own calss extending overlay:

  • If your POI requires a Drawable that needs to be rotated at runtime (i.e. an arrow pointing in a changing direction)
  • If you want to draw a route without markers
  • If you want to draw something that can't be easly made from a drawable

Regards.




回答2:


An ItemizedOverlay essentially does what you're talking about: it contains an itemized list of OverlayItem objects to draw.



来源:https://stackoverflow.com/questions/13671475/confusion-between-overlay-overlayitem-and-itemizedoverley

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