0

Currently using ItemizedIconOverlay from OSMdroid library

import org.osmdroid.views.overlay.ItemizedIconOverlay;

And I set my parameters this way:

public class OsmActivity extends Activity implements LocationListener{
    private ItemizedIconOverlay<OverlayItem> mMyLocationOverlay
...
}

And I add items this way:

    mItems.add(new OverlayItem("Title 2", "Sample Description2", new GeoPoint((int)(35.1359488*1E6),(int)(33.3336289*1E6))));
    mItems.add(new OverlayItem("Title 3", "Sample Description3", new GeoPoint((int)(35.1259488*1E6),(int)(33.3436289*1E6))));
    this.mMyLocationOverlay = new ItemizedIconOverlay<OverlayItem>(mItems, myCustomIconMarker, new Glistener(), mResourceProxy);

Now how do I do this with this ItemizedOverlayWithFocus ?

http://code.google.com/p/osmdroid/source/browse/trunk/osmdroid-android/src/org/osmdroid/views/overlay/ItemizedOverlayWithFocus.java?r=802

This is what's confusing me:

ItemizedOverlayWithFocus<T extends OverlayItem> extends ItemizedOverlay<T>

What does T mean?

Can someone post example code that uses it?

SeyedPooya Soofbaf
  • 2,654
  • 2
  • 29
  • 31
bubbly
  • 495
  • 1
  • 10
  • 22

1 Answers1

1

haven't actually tried writing any code to back this up, but having a quick look at the code in question, you should be able to do exactly as you are doing, but substitute ItemizedIconOverlay with ItemizedOverlayWithFocus

the is all to do with generics and templating, concepts which allow us to make more type safe objects.

so where you have ItemizedIconOverlay you are saying that the internals of ItemizedIconOverlay will only ever work with OverlayItems (or subclasses thereof).

the same is applied to ItemizedOverlayWithFocus

what that's saying is that when you create your constructor (and all the item arrays etc that you put into it), the type of data you specify in the chevrons <> must be of type OverlayItem, or must extend OverlayItem.

so in theory your code could be changed to

    private ItemizedOverlayWithFocus<OverlayItem> mMyLocationOverlay;
...
mItems.add....

the trick comes with the constructor, as the WithFocus class has different constructors to those you've used above you have a choice of (where this will work as long as you're in an activity class as you need a Context object)

    this.mMyLocationOverlay = newItemizedOverlayWithFocus<OverlayItem>(this, mItems, new GListener());

or this.mMyLocationOverlay = newItemizedOverlayWithFocus(this, mItems, new GListener(), mResourceProxy);

or (you'll have to fill in the quoted 'blanks' on this one)

    this.mMyLocationOverlay = newItemizedOverlayWithFocus<OverlayItem>(this, mItems, 'Drawable marker', 'Point markerHotspot', 'Drawable markerFocusedBase', 'Point markerFocusedHotspot', 'int focusedBackgroundColour', new GListener(), mResourceProxy);
rspython
  • 229
  • 1
  • 9
  • In the ItemizedOverlayWithFocus there is this: ItemizedOverlayWithFocus extends ItemizedOverlay where in the ItemizedOverlay it's ... T vs Item. what's the difference? – bubbly May 11 '12 at 13:48
  • 1
    none, it's a variable name. (technically it's a template type but think of it as a special variable name) if you look at the sourcecode for both of them, in the one where it's 'T' (which is the defacto accepted standard name in generics), whereever you find a variable of type T, it will be of whatever type you pass in between the chevrons, so for anywhere where there's a variable of type 'T', it will be of type OverlayItem. the other class is the same, but they have called their template variable 'Item' instead of 'T' – rspython May 11 '12 at 14:09
  • best point of reference for understanding generics is the java generics tutorial http://docs.oracle.com/javase/tutorial/java/generics/index.html – rspython May 11 '12 at 14:12