org.osmdroid.views.overlay
Class Overlay

java.lang.Object
  extended by org.osmdroid.views.overlay.Overlay
All Implemented Interfaces:
OverlayConstants
Direct Known Subclasses:
DirectedLocationOverlay, ItemizedOverlay, MyLocationOverlay, PathOverlay, ScaleBarOverlay, SimpleLocationOverlay, TilesOverlay

public abstract class Overlay
extends Object
implements OverlayConstants

Base class representing an overlay which may be displayed on top of a MapView. To add an overlay, subclass this class, create an instance, and add it to the list obtained from getOverlays() of MapView. This class implements a form of Gesture Handling similar to GestureDetector.SimpleOnGestureListener and GestureDetector.OnGestureListener. The difference is there is an additional argument for the item.

Author:
Nicolas Gramlich

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  ResourceProxy mResourceProxy
           
protected  float mScale
           
protected static float SHADOW_X_SKEW
           
protected static float SHADOW_Y_SCALE
           
 
Fields inherited from interface org.osmdroid.views.util.constants.OverlayConstants
DEBUGMODE, DEFAULT_ZOOMLEVEL_MINIMAP_DIFFERENCE, NOT_SET
 
Constructor Summary
Overlay(android.content.Context ctx)
           
Overlay(ResourceProxy pResourceProxy)
           
 
Method Summary
protected abstract  void draw(android.graphics.Canvas c, MapView osmv, boolean shadow)
          Draw the overlay over the map.
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.
protected static int getSafeMenuId()
          Since the menu-chain will pass through several independent Overlays, menu IDs cannot be fixed at compile time.
protected static int getSafeMenuIdSequence(int count)
          Similar to , except this reserves a sequence of IDs of length .
 boolean isEnabled()
          Specifies if the Overlay is marked to be enabled.
 void onDetach(MapView mapView)
          Override to perform clean up of resources before shutdown.
 boolean onDoubleTap(android.view.MotionEvent e, MapView mapView)
          By default does nothing (return false).
 boolean onDoubleTapEvent(android.view.MotionEvent e, MapView mapView)
          By default does nothing (return false).
 boolean onDown(android.view.MotionEvent e, MapView mapView)
          By default does nothing (return false).
 boolean onFling(android.view.MotionEvent pEvent1, android.view.MotionEvent pEvent2, float pVelocityX, float pVelocityY, MapView pMapView)
          By default does nothing (return false).
 boolean onKeyDown(int keyCode, android.view.KeyEvent event, MapView mapView)
          By default does nothing (return false).
 boolean onKeyUp(int keyCode, android.view.KeyEvent event, MapView mapView)
          By default does nothing (return false).
 boolean onLongPress(android.view.MotionEvent e, MapView mapView)
          By default does nothing (return false).
 boolean onScroll(android.view.MotionEvent pEvent1, android.view.MotionEvent pEvent2, float pDistanceX, float pDistanceY, MapView pMapView)
          By default does nothing (return false).
 void onShowPress(android.view.MotionEvent pEvent, MapView pMapView)
           
 boolean onSingleTapConfirmed(android.view.MotionEvent e, MapView mapView)
          By default does nothing (return false).
 boolean onSingleTapUp(android.view.MotionEvent e, MapView mapView)
          By default does nothing (return false).
 boolean onTouchEvent(android.view.MotionEvent event, MapView mapView)
          You can prevent all(!)
 boolean onTrackballEvent(android.view.MotionEvent event, MapView mapView)
          By default does nothing (return false).
 void setEnabled(boolean pEnabled)
          Sets whether the Overlay is marked to be enabled.
 
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
See Also:
Constant Field Values

SHADOW_Y_SCALE

protected static final float SHADOW_Y_SCALE
See Also:
Constant Field Values

mResourceProxy

protected final ResourceProxy mResourceProxy

mScale

protected final float mScale
Constructor Detail

Overlay

public Overlay(android.content.Context ctx)

Overlay

public Overlay(ResourceProxy pResourceProxy)
Method Detail

setEnabled

public void setEnabled(boolean pEnabled)
Sets whether the Overlay is marked to be enabled. This setting does nothing by default, but should be checked before calling draw().


isEnabled

public boolean isEnabled()
Specifies if the Overlay is marked to be enabled. This should be checked before calling draw().

Returns:
true if the Overlay is marked enabled, false otherwise

getSafeMenuId

protected static final int getSafeMenuId()
Since the menu-chain will pass through several independent Overlays, menu IDs cannot be fixed at compile time. Overlays should use this method to obtain and store a menu id for each menu item at construction time. This will ensure that two overlays don't use the same id.

Returns:
an integer suitable to be used as a menu identifier

getSafeMenuIdSequence

protected static final int getSafeMenuIdSequence(int count)
Similar to , except this reserves a sequence of IDs of length . The returned number is the starting index of that sequential list.

Returns:
an integer suitable to be used as a menu identifier

draw

protected abstract void draw(android.graphics.Canvas c,
                             MapView osmv,
                             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. Callers should check isEnabled() before calling draw(). By default, draws nothing.


onDetach

public void onDetach(MapView mapView)
Override to perform clean up of resources before shutdown. By default does nothing.


onKeyDown

public boolean onKeyDown(int keyCode,
                         android.view.KeyEvent event,
                         MapView mapView)
By default does nothing (return false). If you handled the Event, return true, otherwise return false. If you returned true none of the following Overlays or the underlying MapView has the chance to handle this event.


onKeyUp

public boolean onKeyUp(int keyCode,
                       android.view.KeyEvent event,
                       MapView mapView)
By default does nothing (return false). If you handled the Event, return true, otherwise return false. If you returned true none of the following Overlays or the underlying MapView has the chance to handle this event.


onTouchEvent

public boolean onTouchEvent(android.view.MotionEvent event,
                            MapView mapView)
You can prevent all(!) other Touch-related events from happening!
By default does nothing (return false). If you handled the Event, return true, otherwise return false. If you returned true none of the following Overlays or the underlying MapView has the chance to handle this event.


onTrackballEvent

public boolean onTrackballEvent(android.view.MotionEvent event,
                                MapView mapView)
By default does nothing (return false). If you handled the Event, return true, otherwise return false. If you returned true none of the following Overlays or the underlying MapView has the chance to handle this event.


onDoubleTap

public boolean onDoubleTap(android.view.MotionEvent e,
                           MapView mapView)
By default does nothing (return false). If you handled the Event, return true, otherwise return false. If you returned true none of the following Overlays or the underlying MapView has the chance to handle this event.


onDoubleTapEvent

public boolean onDoubleTapEvent(android.view.MotionEvent e,
                                MapView mapView)
By default does nothing (return false). If you handled the Event, return true, otherwise return false. If you returned true none of the following Overlays or the underlying MapView has the chance to handle this event.


onSingleTapConfirmed

public boolean onSingleTapConfirmed(android.view.MotionEvent e,
                                    MapView mapView)
By default does nothing (return false). If you handled the Event, return true, otherwise return false. If you returned true none of the following Overlays or the underlying MapView has the chance to handle this event.


onDown

public boolean onDown(android.view.MotionEvent e,
                      MapView mapView)
By default does nothing (return false). If you handled the Event, return true, otherwise return false. If you returned true none of the following Overlays or the underlying MapView has the chance to handle this event.


onFling

public boolean onFling(android.view.MotionEvent pEvent1,
                       android.view.MotionEvent pEvent2,
                       float pVelocityX,
                       float pVelocityY,
                       MapView pMapView)
By default does nothing (return false). If you handled the Event, return true, otherwise return false. If you returned true none of the following Overlays or the underlying MapView has the chance to handle this event.


onLongPress

public boolean onLongPress(android.view.MotionEvent e,
                           MapView mapView)
By default does nothing (return false). If you handled the Event, return true, otherwise return false. If you returned true none of the following Overlays or the underlying MapView has the chance to handle this event.


onScroll

public boolean onScroll(android.view.MotionEvent pEvent1,
                        android.view.MotionEvent pEvent2,
                        float pDistanceX,
                        float pDistanceY,
                        MapView pMapView)
By default does nothing (return false). If you handled the Event, return true, otherwise return false. If you returned true none of the following Overlays or the underlying MapView has the chance to handle this event.


onShowPress

public void onShowPress(android.view.MotionEvent pEvent,
                        MapView pMapView)

onSingleTapUp

public boolean onSingleTapUp(android.view.MotionEvent e,
                             MapView mapView)
By default does nothing (return false). If you handled the Event, return true, otherwise return false. If you returned true none of the following Overlays or the underlying MapView has the chance to handle this event.


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.


Copyright © 2012. All Rights Reserved.