0

目前使用 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 是什么意思?

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

4

1 回答 1

1

实际上并没有尝试编写任何代码来支持这一点,但是快速查看有问题的代码,您应该能够完全按照您的方式进行操作,但是将 ItemizedIconOverlay 替换为 ItemizedOverlayWithFocus

这与泛型和模板有关,这些概念使我们能够制作更多类型安全的对象。

因此,在您拥有 ItemizedIconOverlay 的地方,您是在说 ItemizedIconOverlay 的内部结构只能与 OverlayItems(或其子类)一起使用。

同样适用于 ItemizedOverlayWithFocus

这就是说,当您创建构造函数(以及您放入其中的所有项目数组等)时,您在 V 形 <> 中指定的数据类型必须是 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);
于 2012-05-11T12:50:24.210 回答