How would you go about creating and ItemizedOverlay which covers the entire map?
I have multiple markers on the map which are ItemizedOverlay classes.
I want to create another ItemizedOverlay which covers the entire map to intercept touch events which are not on my markers but the map itself. I have read in other SO questions like this one that the only way to do this is via an ItemizedOverlay->onTap. The problem is I don't know how to create of Drawable marker which covers the entire map.
I have experimented with LinearLayout drawables but it only appears to be able to use a drawable image as a marker.
Here is my code
private class BackgroundOverlay<Item extends OverlayItem> extends ItemizedOverlay<OverlayItem>{
private ArrayList<OverlayItem> overlays = new ArrayList<OverlayItem>();
/**
* @param defaultMarker
*/
public BackgroundOverlay(Drawable defaultMarker,Context context) {
super(boundCenterBottom(defaultMarker));
}
@Override
protected OverlayItem createItem(int i) {
return overlays.get(i);
}
@Override
public int size() {
return overlays.size();
}
public void addOverlay(OverlayItem overlay) {
overlays.add(overlay);
populate();
}
protected boolean onTap(int index){
Toast.makeText(getApplicationContext(), "Touched background",Toast.LENGTH_SHORT).show();
return true;
}
}
and to create the overlay
Drawable d=this.getResources().getDrawable(R.layout.full_screen);
BackgroundOverlay<OverlayItem> lay = new BackgroundOverlay<OverlayItem>(d,this);
overlayItem = new OverlayItem(this.mapView.getMapCenter(), "", "");
lay.addOverlay(overlayItem);
mapOverlays.add(lay);
and the drawable xml
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/blue">
</LinearLayout>
Thanks in advance
Ok so I figured it out. To overlay the entire map you add a simple Overlay subclass with no drawable duh. and use the onTap event.
private class BackgroundOverlay extends Overlay{
public boolean onTap (final GeoPoint p, final MapView mapView){
Toast.makeText(getApplicationContext(), "Touched background",Toast.LENGTH_SHORT).show();
hideOtherFires(mapView.getOverlays());
return true;
}
and instantiate before the other overlays so it goes underneath
//add a background overlay to intercept touches on background
BackgroundOverlay lay = new BackgroundOverlay();
mapOverlays.add(lay);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With