I have a program that is creating an ItemizedOverlay and a map. Everything works fine upon startup.
When you close ande re-open the app, I am using onRestart() to get u
You create your own ItemizedOverlay sublcass when using a MapView. You can add a clear()
method if you want.
A typical custom overlay looks like this. it encapsulates the various OverlayItems displayed on the map in a list.
public class MyItemizedOverlay extends ItemizedOverlay<OverlayItem>{
private List<OverlayItem> mOverlays = new ArrayList<OverlayItem>();
public MyItemizedOverlay(Drawable defaultMarker) {
super(boundCenterBottom(defaultMarker));
}
@Override
protected OverlayItem createItem(int i) {
return mOverlays.get(i);
}
public void addOverlay(OverlayItem overlay) {
mOverlays.add(overlay);
populate();
}
public void removeOverlay(OverlayItem overlay) {
mOverlays.remove(overlay);
populate();
}
public void clear() {
mOverlays.clear();
populate();
}
@Override
public int size() {
return mOverlays.size();
}
}
Methods can be exposed to add / remove individual overlayitems, but also the remove all overlayitems (clear method).
Remove a single overlayitem
MyItemizedOverlay sitesOverlay = (MyItemizedOverlay ) map.getOverlays().get(0);
sitesOverlay.removeOverlay(overlay);
Add a single overlayItem
MyItemizedOverlay sitesOverlay = (MyItemizedOverlay ) map.getOverlays().get(0);
sitesOverlay.addOverlay(new OverlayItem(p, "title", "snippet"));
Remove all overlayItems
MyItemizedOverlay sitesOverlay = (MyItemizedOverlay ) map.getOverlays().get(0);
sitesOverlay.clear();