PATRIK27 / osmdroid

Automatically exported from code.google.com/p/osmdroid
0 stars 0 forks source link

Move towards Google Maps API implementation of ItemizedOverlay #182

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
This is a continuation of Issue 173, but with an organized list of changes so 
the patch is clear.

1. ItemizedOverlay becomes abstract. The idea is that the user will create a 
concrete class that will populate the ItemizedOverlay with Items which are 
cached in ItemizedOverlay (see ItemizedIconOverlay).
2. The constructors for ItemizedOverlay only accept a default marker and a 
ResourceProxy. The default marker passed into ItemizedOverlay must not be null 
- the concrete class is responsible for providing this.
3. Each Item's marker's bounds should be set based on 0,0 being the pixel point 
of the Item's GeoPoint. The boundToHotSpot() function operates accordingly.
4. To draw an icon we can call TileSystem.LatLongToPixelXY() to get the pixel 
point (ItemizedOverlay.draw), bind the marker to the appropriate hotspot 
(ItemizedOverlay.onDrawItem), then draw the icon at the pixel point plus the 
offset of the drawable's bounds (Overlay.drawAt).
5. Hit testing, as implemented in Google Maps API, is very simple - it just 
checks to see if a given hit point is within the bounds of the marker. The 
appropriate way to call hitTest() is to pass a hitX/hitY that is the distance 
from the touch point to the Item's point. So you need to point the point of the 
screen touch and the point of the Item in the same coordinate system and get 
the delta between the two and use that as the hitX and hitY.

Since the ItemizedOverlay's responsibilities are limited and since it is an 
abstract class, we naturally need a concrete class that implements all the 
other features of our (original) ItemizedOverlay. The ItemizedIconOverlay class 
implements:

1. Default marker creation if the user doesn't want to provide one. The only 
change is that you cannot pass null as the defaultMarker in the constructor. If 
you want the ItemizedIconOverlay to create its own defaultMarker, then use the 
constructor without the pDefaultMarker. Naturally, individual Items can still 
override the default marker with their own marker.
2. All gesture handling. This includes activateSelectedItems.
3. Drawn items limit handling.

Changes to be aware of:
1. The way the Google Maps ItemizedOverlay works is that the concrete class 
calls populate(), which triggers the abstract class to request the size() from 
the concrete class, and then request items 0 to size()-1 from the concrete 
class. So you cannot pass a List into ItemizedIconOverlay and then add to the 
list and expect the items to show up. Therefore the ItemizedIconOverlay 
provides addItem and removeItem methods that add the item to the list and call 
populate(). Maybe we should consider passing in an array instead of a list of 
initial items in the constructor.
2. Users will have to change most references of ItemizedOverlay to 
ItemizedIconOverlay in their code.

The focused item overlays will be adjusted to operate properly and will be kept 
separate at this point, but Google Maps is geared towards having a single 
overlay that does both non-focused and focused Items so we should consider that 
next.

We should also implement shadow drawing at some point. It appears to be very 
easy.

Original issue reported on code.google.com by kurtzm...@gmail.com on 12 Mar 2011 at 4:00

Attachments:

GoogleCodeExporter commented 8 years ago
Issue 173 has been merged into this issue.

Original comment by kurtzm...@gmail.com on 12 Mar 2011 at 4:02

GoogleCodeExporter commented 8 years ago
After a few days of testing (and a few fixes), I am very happy with the patch. 
Since there are no objections, I am going to apply this patch. I will leave the 
ticket open for any issues that might arise.

Original comment by kurtzm...@gmail.com on 19 Mar 2011 at 5:39

GoogleCodeExporter commented 8 years ago
One additional feature from the original patch - I added a working setFocus() 
implementation. If the drawable is a StateListDrawable and the user clicks an 
item, then the item will become focused and it will display the appropriate 
Drawable for the "focused" state.

Our focused overlay doesn't take advantage of this yet, but I think we will 
soon. Maybe some nicer focus bubbles too!

Original comment by kurtzm...@gmail.com on 19 Mar 2011 at 5:45

GoogleCodeExporter commented 8 years ago
This issue was updated by revision r887.

Applies ItemizedOverlay patch. See issue 182 for full list of changes.

Original comment by kurtzm...@gmail.com on 19 Mar 2011 at 5:46

GoogleCodeExporter commented 8 years ago
This issue has been implemented and has been tested pretty thoroughly. The 
paradigm is easy to work with and it mirrors the Google API without losing any 
functionality. This issue can be closed.

Original comment by kurtzm...@gmail.com on 15 May 2011 at 11:45