0

已经有一个覆盖,在地图视图上绘制了一些东西。我想在地图视图中添加另一个叠加层和自定义项目。什么都没有显示。我的代码有什么问题?多谢了。

我的 ItemizedOverlay 子类

public class PinItemizedOverlay extends ItemizedOverlay {
private static int MAX_PIN = 3;
private OverlayItem overlays[] = new OverlayItem[MAX_PIN];

private int index = 0;
private boolean full = false;
private Context context;

public PinItemizedOverlay(Context context, Drawable defaultMarker) {
    //super(boundCenterBottom(defaultMarker));
    super(boundCenterBottom(defaultMarker));
    this.context = context;
}

@Override
public OverlayItem createItem(int index) {
    return overlays[index];
}

public int size(){
    if (full) {
        return overlays.length;
    } else {
        return index;
    }
}

public void addOverlay(OverlayItem overlay) {
    if (index <     MAX_PIN) {
        overlays[index] = overlay;
    } else {
        return;
    }
    index++;
    populate();
}
}

我的自定义叠加项目

 public class LocationPinItem extends OverlayItem{

    public LocationEntity location;

    public LocationPinItem(GeoPoint point, int iconRes, LocationEntity location){
        //super(point,null,null);
        super(point, null, null);
        Drawable marker = getApplicationContext().getResources().getDrawable(iconRes);
        super.setMarker(marker );
        this.location = location;

    }

}

以及我添加自定义项目的功能(它是一个放置图钉):

private void createMarkerAt(LocationEntity location, String extra, int iconRes, boolean clear, boolean animate) {
    if(location == null) {
        return;
    }
    GeoPoint point = new GeoPoint((int) (location.latitude * 1E6), (int) (location.longitude * 1E6));

    LocationPinItem pinItem = new LocationPinItem(point,R.drawable.ic_swap,location);
    PinItemizedOverlay pinOverlay = new PinItemizedOverlay(getApplicationContext(),mMapDrawable) ;
    pinOverlay.addOverlay(pinItem);


mMapView.removeAllViews();
mMapView.postInvalidate();

    mMapView.getOverlays().add(pinOverlay);

    if(animate) {
        mMapView.getController().animateTo(location.toGeoPoint());
    }


}
4

1 回答 1

0

没关系,我想通了:新添加的叠加层遮挡了之前的叠加层

于 2012-09-10T02:17:32.190 回答