使用ItemizedOverlayWithFocus的代码

时间:2012-05-11 12:09:45

标签: android osmdroid

目前在OSMdroid库中使用ItemizedIconOverlay

import org.osmdroid.views.overlay.ItemizedIconOverlay;

我以这种方式设置参数:

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

我以这种方式添加项目:

    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);

现在我如何使用此ItemizedOverlayWithFocus?

执行此操作

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

这令我感到困惑:

ItemizedOverlayWithFocus<T extends OverlayItem> extends ItemizedOverlay<T>

T是什么意思?

有人可以发布使用它的示例代码吗?

1 个答案:

答案 0 :(得分:1)

实际上没有尝试编写任何代码来支持这一点,但是快速查看相关代码,您应该能够完全按照自己的意思去做,但用ItemizedOverlayWithFocus替换ItemizedIconOverlay

这与仿制药和模板有关,这些概念允许我们制作更多类型安全的对象。

所以你有ItemizedIconOverlay,你说ItemizedIconOverlay的内部只会使用OverlayItems(或其子类)。

同样适用于ItemizedOverlayWithFocus

这就是说当你创建你的构造函数(以及你放入它的所有项目数组等)时,你在v形符号中指定的数据类型&lt;&gt;必须是OverlayItem类型,或者必须扩展OverlayItem。

所以理论上你的代码可以改为

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

这个技巧来自构造函数,因为WithFocus类具有与上面使用的构造函数不同的构造函数 你可以选择(只要你在一个活动类中就可以工作,因为你需要一个Context对象)

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

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

或(你必须在这个上填写引用的'空白')

    this.mMyLocationOverlay = newItemizedOverlayWithFocus<OverlayItem>(this, mItems, 'Drawable marker', 'Point markerHotspot', 'Drawable markerFocusedBase', 'Point markerFocusedHotspot', 'int focusedBackgroundColour', new GListener(), mResourceProxy);