com.google.android.maps
Class Overlay

java.lang.Object
  extended by com.google.android.maps.Overlay
Direct Known Subclasses:
ItemizedOverlay, MyLocationOverlay

public abstract class Overlay
extends java.lang.Object

Base class representing an overlay which may be displayed on top of a map. To add an overlay, subclass this class, create an instance, and add it to the list obtained from MapView.getOverlays().

In order to allow a user's touch to snap to a point, the subclass should implement the Overlay.Snappable interface.


Nested Class Summary
static interface Overlay.Snappable
          Interface definition for overlays that contain items that can be snapped to (for example, when the user invokes a zoom, this could be called allowing the user to snap the zoom to an interesting point.)
 
Field Summary
protected static float SHADOW_X_SKEW
          X Skew value for creating a marker shadow in perspective.
protected static float SHADOW_Y_SCALE
          Y Scale value for creating a marker shadow in perspective.
 
Constructor Summary
Overlay()
           
 
Method Summary
 void draw(android.graphics.Canvas canvas, MapView mapView, boolean shadow)
          Draw the overlay over the map.
 boolean draw(android.graphics.Canvas canvas, MapView mapView, boolean shadow, long when)
          Draw call for animated overlays.
protected static void drawAt(android.graphics.Canvas canvas, android.graphics.drawable.Drawable drawable, int x, int y, boolean shadow)
          Convenience method to draw a Drawable at an offset.
 boolean onKeyDown(int keyCode, android.view.KeyEvent event, MapView mapView)
          Handle a key down event.
 boolean onKeyUp(int keyCode, android.view.KeyEvent event, MapView mapView)
          Handle a key up event.
 boolean onTap(GeoPoint p, MapView mapView)
          Handle a "tap" event.
 boolean onTouchEvent(android.view.MotionEvent e, MapView mapView)
          Handle a touch event.
 boolean onTrackballEvent(android.view.MotionEvent event, MapView mapView)
          Handle a trackball event.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

SHADOW_X_SKEW

protected static final float SHADOW_X_SKEW
X Skew value for creating a marker shadow in perspective.

See Also:
Constant Field Values

SHADOW_Y_SCALE

protected static final float SHADOW_Y_SCALE
Y Scale value for creating a marker shadow in perspective.

See Also:
Constant Field Values
Constructor Detail

Overlay

public Overlay()
Method Detail

drawAt

protected static void drawAt(android.graphics.Canvas canvas,
                             android.graphics.drawable.Drawable drawable,
                             int x,
                             int y,
                             boolean shadow)
Convenience method to draw a Drawable at an offset. x and y are pixel coordinates. You can find appropriate coordinates from latitude/longitude using the MapView.getProjection() method on the MapView passed to you in draw(Canvas, MapView, boolean).

Parameters:
shadow - If true, draw only the drawable's shadow. Otherwise, draw the drawable itself.

onTouchEvent

public boolean onTouchEvent(android.view.MotionEvent e,
                            MapView mapView)
Handle a touch event. By default does nothing and returns false.

Parameters:
e - The motion event.
mapView - the MapView that generated the touch event
Returns:
True if the tap was handled by this overlay.

onTrackballEvent

public boolean onTrackballEvent(android.view.MotionEvent event,
                                MapView mapView)
Handle a trackball event. By default does nothing and returns false.

Parameters:
event - The motion event.
mapView - the MapView that generated the trackball event
Returns:
True if the tap was handled by this overlay.

onKeyDown

public boolean onKeyDown(int keyCode,
                         android.view.KeyEvent event,
                         MapView mapView)
Handle a key down event. By default does nothing and returns false.

Parameters:
keyCode - The key code.
event - The key event.
mapView - the MapView that generated the key event
Returns:
True If the tap was handled by this overlay.

onKeyUp

public boolean onKeyUp(int keyCode,
                       android.view.KeyEvent event,
                       MapView mapView)
Handle a key up event. By default does nothing and returns false.

Parameters:
keyCode - The key code
event - The key event
mapView - the MapView that generated the key event
Returns:
True if the tap was handled by this overlay.

onTap

public boolean onTap(GeoPoint p,
                     MapView mapView)
Handle a "tap" event. This can be either a touchscreen tap anywhere on the map, or a trackball click on the center of the map. By default does nothing and returns false.

Parameters:
p - The point that has been tapped.
mapView - the MapView that generated the tap event
Returns:
True if the tap was handled by this overlay.

draw

public void draw(android.graphics.Canvas canvas,
                 MapView mapView,
                 boolean shadow)
Draw the overlay over the map. This will be called on all active overlays with shadow=true, to lay down the shadow layer, and then again on all overlays with shadow=false. By default, draws nothing.

Parameters:
canvas - The Canvas upon which to draw. Note that this may already have a transformation applied, so be sure to leave it the way you found it.
mapView - the MapView that requested the draw. Use MapView.getProjection() to convert between on-screen pixels and latitude/longitude pairs.
shadow - If true, draw the shadow layer. If false, draw the overlay contents.

draw

public boolean draw(android.graphics.Canvas canvas,
                    MapView mapView,
                    boolean shadow,
                    long when)
Draw call for animated overlays. By default, calls through to draw(Canvas, MapView, boolean) and returns false.

Parameters:
canvas - The Canvas upon which to draw. Note that this may already have a transformation applied, so be sure to leave it the way you found it.
mapView - the MapView that requested the draw. Use MapView.getProjection() to convert between on-screen pixels and latitude/longitude pairs.
shadow - If true, draw the shadow layer. If false, draw the overlay contents.
when - The timestamp of the draw.
Returns:
True if you need to be drawn again right away; false otherwise. Default implementation returns false.