Question

There is already an overlay, drawing something on a map view. I want to add another overlay and a customized item to the map view. Nothing shows. What's wrong with my code? Thanks heaps.

My sub-class of 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();
}
}

My customized overlay item

 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;

    }

}

And the function where I add the customized item (it's a drop pin):

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


}
Was it helpful?

Solution

never mind, I figured it out: the newly-added overlay occludes the previous overlay

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top