3

I am working on a MapView app, and would like to place a nice little easter egg in the program. What I am trying to do is have an overlayitem that is basically invisible, but when tapped will trigger an event to show a view.

Now on the iPhone i accomplished this by using setHidden:true on the annotation I didn't want visible.. the annotation was still there and still was clickable, but you could not see it.

I am trying to find some equivalent method on the overlayItem in Android, but find nothing. Is my only option to accopmlish this to find/create a transparent image and add it as an overlay to the mapView? I can do this if I have to, but are there any other options? And if not can anyone point me to a relatively small transparent image?

user756212
  • 522
  • 5
  • 16

3 Answers3

5

I know you found a way to hide your overlay but there is more elegant way to do this. Make a custom class of your overlay:

public class MapOverlay extends Overlay{

    private Boolean visible;

    public MapOverlay(){
        this.visible = true;
    }   

    public void draw(Canvas canvas, MapView mapv, boolean shadow){
        super.draw(canvas, mapv, shadow);

        if (visible) {
            // draw what you want
        }
    }

    public Boolean isVisible() {
        return visible;
    }

    public void isVisible(Boolean visible) {
        this.visible = visible;
    }

    public void toggleVisible() {
        this.visible = !visible;
    }
}

Then in your activity, add overlays as usual:

mapView.getOverlays().addOverlay(new MapOverlay());

Later, if you want to show/hide your overlay, simply call:

mapView.getOverlays().get(0).toggleVisible();

or:

mapView.getOverlays().get(0).isVisible(false);

Hope it helps.

Romain Piel
  • 11,017
  • 15
  • 71
  • 106
0

You can make a clickable imageview (set the width/height accordingly and the color to be transparent) on top of your map view, which when clicked, triggers the easter egg. However it might be difficult to position it correctly..

Aside from that, I can imagine using a custom view where you override the onTouch function to trigger the easter egg if x,y coordinates are within a box.. and it otherwise gets processed by the map view. But this sounds like it could be a lot of work for an easter egg..

f20k
  • 3,106
  • 3
  • 23
  • 32
  • I wound up just adding an overlay that was basically a transparent image as an itemizedoverlayitem, and it worked fine. Thank you for the other ideas. – user756212 May 31 '11 at 14:24
0

I found the easiest solution was to just use an invisible drawable and add it as an overlayitem, so this is what I did and it works as expected.

user756212
  • 522
  • 5
  • 16