com.mapquest.android.maps
Class PolygonOverlay

java.lang.Object
  extended by com.mapquest.android.maps.Overlay
      extended by com.mapquest.android.maps.PolygonOverlay

public class PolygonOverlay
extends Overlay

PolygonOverlay is an extension of a map Overlay intended for drawing a polygon on a MapView


Nested Class Summary
 
Nested classes/interfaces inherited from class com.mapquest.android.maps.Overlay
Overlay.OverlayTapListener, Overlay.OverlayTouchEventListener, Overlay.OverlayTrackballEventListener, Overlay.Snappable
 
Field Summary
 
Fields inherited from class com.mapquest.android.maps.Overlay
BOTTOM, CENTER, CENTER_HORIZONTAL, CENTER_VERTICAL, LEFT, RIGHT, SHADOW_X_SKEW, SHADOW_Y_SCALE, tapListener, TOP, touchListener, trackballListener
 
Constructor Summary
PolygonOverlay()
          Initializes a new PolygonOverlay Requires the caller to set the line data using one of the methods: setData(List) setData(List, boolean) setData(List, BoundingBox)
PolygonOverlay(android.graphics.Paint linePaint)
          Initializes a new PolygonOverlay with a Paint object used for the polygon's color, alpha, and stroke width (as defined by Paint.getColor(), Paint.getAlpha(), and Paint.getStrokeWidth()) Requires the caller to set the line data using one of the methods: setData(List) setData(List, boolean) setData(List, BoundingBox)
 
Method Summary
 void destroy()
          Cleans up internal objects used in this overlay by setting them to null
 void draw(android.graphics.Canvas canvas, MapView mapView, boolean shadow)
          Contains operations to draw the polygon.

This method performs some checks to only draw the points that are within the map bounds, however, it does not do any optimization of the points.
 boolean onTap(GeoPoint gp, MapView mapView)
          If the overlay has an OverlayTapListener and the tapped point is near the line, pass the event to the Overlay.tapListener
 boolean onTouchEvent(android.view.MotionEvent evt, MapView mapView)
          If the overlay has an OverlayTouchEventListener and the tapped point is within the polygon, pass the event to the Overlay.touchListener
 boolean onTrackballEvent(android.view.MotionEvent evt, MapView mapView)
          If the overlay has an OverlayTrackballEventListener and the trackball point is within the polygon, pass the event to the Overlay.trackballListener
 void setBoundingBox(BoundingBox boundingBox)
          Sets the line's BoundingBox to be used for clipping within the draw command
 void setData(java.util.List<GeoPoint> data)
          Sets the data to be used to draw as a polygon as provided by a List of GeoPoint objects.
 void setData(java.util.List<GeoPoint> data, boolean recomputeBoundingBox)
          Sets the data to be used to draw as a polygon as provided by a List of GeoPoint objects.
 void setData(java.util.List<GeoPoint> data, BoundingBox bbox)
          Sets the data to be used to draw as a polygon as provided by a List of GeoPoint objects and BoundingBox that acts as a clipping region for the overlay.
 void setLinePaint(android.graphics.Paint paint)
          Sets a Paint object used for this PolygonOverlay's color, alpha, and stroke width (as defined by Paint.getColor(), Paint.getAlpha(), and Paint.getStrokeWidth())
 void setPointPaint(android.graphics.Paint paint)
          Sets a Paint object to be used to draw defined points along the PolygonOverlay that correspond to the line's #data points
 void setShowPoints(boolean showPoints, android.graphics.Paint pointPaint)
          Sets whether the polygon overlay should show extra definition around the line's #data points
 
Methods inherited from class com.mapquest.android.maps.Overlay
draw, drawAt, getKey, getZIndex, onKeyDown, onKeyUp, setAlignment, setKey, setTapListener, setTouchEventListener, setTrackballEventListener, setZIndex
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PolygonOverlay

public PolygonOverlay()
Initializes a new PolygonOverlay Requires the caller to set the line data using one of the methods:


PolygonOverlay

public PolygonOverlay(android.graphics.Paint linePaint)
Initializes a new PolygonOverlay with a Paint object used for the polygon's color, alpha, and stroke width (as defined by Paint.getColor(), Paint.getAlpha(), and Paint.getStrokeWidth()) Requires the caller to set the line data using one of the methods:

Parameters:
linePaint - object reference for PolygonOverlay's color, alpha, and stroke width
Method Detail

setData

public void setData(java.util.List<GeoPoint> data,
                    BoundingBox bbox)
Sets the data to be used to draw as a polygon as provided by a List of GeoPoint objects and BoundingBox that acts as a clipping region for the overlay. If the data provided is not a closed polygon, the last point will be set to the first point in order to close the polygon.

Parameters:
data - list of GeoPoint objects used as drawing coordinates to draw the line
bbox - used to clip the drawing of the polygon

setData

public void setData(java.util.List<GeoPoint> data,
                    boolean recomputeBoundingBox)
Sets the data to be used to draw as a polygon as provided by a List of GeoPoint objects. If the data provided is not a closed polygon, the last point will be set to the first point in order to close the polygon.

Parameters:
data - list of GeoPoint objects used as drawing coordinates to draw the line
recomputeBoundingBox - true is the overlay should automatically recalculate the entire bounding box necessary to draw the overlay,
false if the overlay's current BoundingBox should be retained

setData

public void setData(java.util.List<GeoPoint> data)
Sets the data to be used to draw as a polygon as provided by a List of GeoPoint objects. If the data provided is not a closed polygon, the last pont will be set to the first point in order to close the polygon.

Parameters:
data - list of GeoPoint objects used as drawing coordinates to draw the overlay

setLinePaint

public void setLinePaint(android.graphics.Paint paint)
Sets a Paint object used for this PolygonOverlay's color, alpha, and stroke width (as defined by Paint.getColor(), Paint.getAlpha(), and Paint.getStrokeWidth())

Parameters:
paint - object reference for PolygonOverlay's color, alpha, and stroke width

setShowPoints

public void setShowPoints(boolean showPoints,
                          android.graphics.Paint pointPaint)
Sets whether the polygon overlay should show extra definition around the line's #data points

Parameters:
showPoints - true if the polygon's points should be shown, false if the polygon should be a consistent color
paint - object reference for PolygonOverlay's stroke width

setPointPaint

public void setPointPaint(android.graphics.Paint paint)
Sets a Paint object to be used to draw defined points along the PolygonOverlay that correspond to the line's #data points

Parameters:
paint - object reference for PolygonOverlay's stroke width

setBoundingBox

public void setBoundingBox(BoundingBox boundingBox)
Sets the line's BoundingBox to be used for clipping within the draw command

Parameters:
boundingBox - the boundingBox to be used for clipping

draw

public void draw(android.graphics.Canvas canvas,
                 MapView mapView,
                 boolean shadow)
Contains operations to draw the polygon.

This method performs some checks to only draw the points that are within the map bounds, however, it does not do any optimization of the points. It is up to the creator to provide an efficient set of data (e.g not to include large amounts of points outside the mapView - you can always modify the line's data using setData(List) to optimize performance)

Overrides:
draw in class Overlay
Parameters:
canvas - drawing canvas of the mapView
mapView - mapView where this request was started
shadow - draw the shadow or not on the current pass

onTap

public boolean onTap(GeoPoint gp,
                     MapView mapView)
If the overlay has an OverlayTapListener and the tapped point is near the line, pass the event to the Overlay.tapListener

Overrides:
onTap in class Overlay
Parameters:
gp - the tapped point
mapView - the host MapView object
Returns:
true if the tapped point was near the line and there was a tapListener on the overlay, false if not

onTouchEvent

public boolean onTouchEvent(android.view.MotionEvent evt,
                            MapView mapView)
If the overlay has an OverlayTouchEventListener and the tapped point is within the polygon, pass the event to the Overlay.touchListener

Overrides:
onTouchEvent in class Overlay
Parameters:
evt - the touch event
mapView - the host MapView object
Returns:
true if the touched point was witin the polygon and there was a touchListener on the overlay, false if not

onTrackballEvent

public boolean onTrackballEvent(android.view.MotionEvent evt,
                                MapView mapView)
If the overlay has an OverlayTrackballEventListener and the trackball point is within the polygon, pass the event to the Overlay.trackballListener

Overrides:
onTrackballEvent in class Overlay
Parameters:
evt - the Trackball event
mapView - the host MapView object
Returns:

destroy

public void destroy()
Cleans up internal objects used in this overlay by setting them to null

Overrides:
destroy in class Overlay