com.google.gwt.maps.client.overlay
Class Polygon

java.lang.Object
  extended by com.google.gwt.maps.client.overlay.Overlay
      extended by com.google.gwt.maps.client.overlay.Overlay.ConcreteOverlay
          extended by com.google.gwt.maps.client.overlay.Polygon

public final class Polygon
extends Overlay.ConcreteOverlay

This is a map overlay that draws a polygon on the map, using the vector drawing facilities of the browser if they are available, or an image overlay from Google servers otherwise. This is very similar to a Polyline, except that you can additionally specify a fill color and opacity.


Nested Class Summary
 
Nested classes/interfaces inherited from class com.google.gwt.maps.client.overlay.Overlay
Overlay.ConcreteOverlay
 
Field Summary
 
Fields inherited from class com.google.gwt.maps.client.overlay.Overlay
jsoPeer
 
Constructor Summary
Polygon(LatLng[] points)
          Create a Polygon from an array of points.
Polygon(LatLng[] points, java.lang.String strokeColor, int strokeWeight, double strokeOpacity, java.lang.String fillColor, double fillOpacity)
          Create a polygon from an array of points, specifying optional parameters.
Polygon(LatLng[] points, java.lang.String strokeColor, int strokeWeight, double strokeOpacity, java.lang.String fillColor, double fillOpacity, PolygonOptions options)
          Create a polygon from an array of points, specifying optional parameters.
 
Method Summary
 void addPolygonCancelLineHandler(PolygonCancelLineHandler handler)
          This event is fired when the polygon is being edited and the edit is canceled.
 void addPolygonClickHandler(PolygonClickHandler handler)
          This event is fired when the polygon is clicked.
 void addPolygonEndLineHandler(PolygonEndLineHandler handler)
          This event is fired when the polygon is being edited and the edit is completed.
 void addPolygonLineUpdatedHandler(PolygonLineUpdatedHandler handler)
          This event is fired when the polygon has a vertex inserted.
 void addPolygonMouseOutHandler(PolygonMouseOutHandler handler)
          This event is fired when the mouse moves out of a polygon.
 void addPolygonMouseOverHandler(PolygonMouseOverHandler handler)
          This event is fired when the mouse moves over a polygon.
 void addPolygonRemoveHandler(PolygonRemoveHandler handler)
          This event is fired when the polygon is removed from the map, using MapWidget.removeOverlay(com.google.gwt.maps.client.overlay.Overlay) or MapWidget.clearOverlays().
 void addPolygonVisibilityChangedHandler(PolygonVisibilityChangedHandler handler)
          This event is fired when the polygon is clicked.
 void deleteVertex(int index)
          Removes with the given index in the polygon and updates the shape of the polygon accordingly.
static Polygon fromEncoded(EncodedPolyline[] polylines)
          Create a polygon from an array of polylines.
static Polygon fromEncoded(EncodedPolyline[] polylines, boolean fill, java.lang.String color, double opacity, boolean outline)
          Create a polygon from an array of polylines.
 double getArea()
          Returns the area (in square meters) of the polygon, assuming a spherical Earth.
 LatLngBounds getBounds()
          Returns the bounds for this polygon.
 LatLng getVertex(int index)
          Returns the position of the specified vertex in the polygon.
 int getVertexCount()
          Returns the number of vertices in the polygon.
 boolean isVisible()
          Returns true if the polygon is visible on the map.
 void removePolygonCancelLineHandler(PolygonCancelLineHandler handler)
          Removes a single handler of this map previously added with addPolygonCancelLineHandler(PolygonCancelLineHandler).
 void removePolygonClickHandler(PolygonClickHandler handler)
          Removes a single handler of this map previously added with addPolygonClickHandler(PolygonClickHandler).
 void removePolygonEndLineHandler(PolygonEndLineHandler handler)
          Removes a single handler of this map previously added with addPolygonEndLineHandler(PolygonEndLineHandler).
 void removePolygonLineUpdatedHandler(PolygonLineUpdatedHandler handler)
          Removes a single handler of this map previously added with addPolygonLineUpdatedHandler(PolygonLineUpdatedHandler).
 void removePolygonMouseOutHandler(PolygonMouseOutHandler handler)
          Removes a single handler of this map previously added with addPolygonMouseOutHandler(PolygonMouseOutHandler).
 void removePolygonMouseOverHandler(PolygonMouseOverHandler handler)
          Removes a single handler of this map previously added with addPolygonMouseOverHandler(PolygonMouseOverHandler).
 void removePolygonRemoveHandler(PolygonRemoveHandler handler)
          Removes a single handler of this map previously added with addPolygonRemoveHandler(PolygonRemoveHandler).
 void removePolygonVisibilityChangedHandler(PolygonVisibilityChangedHandler handler)
          Removes a single handler of this map previously added with addPolygonVisibilityChangedHandler(PolygonVisibilityChangedHandler) .
 void setDrawingEnabled()
          Allows a user to construct (or modify) a Polygon object by clicking on additional points on the map.
 void setDrawingEnabled(PolyEditingOptions opts)
          Enable drawing as in setDrawingEnabled() but with control over the polygon drawing parameters.
 void setEditingEnabled(boolean enabled)
          Allows modification of an existing Polygon chain of points.
 void setEditingEnabled(PolyEditingOptions opts)
          Enable editing as in setEditingEnabled(boolean), but with control over the drawing parameters.
 void setFillStyle(PolyStyleOptions style)
          Changes the style of the polygon fill.
 void setStrokeStyle(PolyStyleOptions style)
          Changes the style of the polylgon outline.
 void setVisible(boolean visible)
          Show or hide the polygon.
 boolean supportsHide()
          Returns true if this environment supports the setVisible(boolean) method.
 
Methods inherited from class com.google.gwt.maps.client.overlay.Overlay.ConcreteOverlay
copy, initialize, redraw, remove
 
Methods inherited from class com.google.gwt.maps.client.overlay.Overlay
getZIndex
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Polygon

public Polygon(LatLng[] points)
Create a Polygon from an array of points.

Parameters:
points - the points to construct the polygon.

Polygon

public Polygon(LatLng[] points,
               java.lang.String strokeColor,
               int strokeWeight,
               double strokeOpacity,
               java.lang.String fillColor,
               double fillOpacity)
Create a polygon from an array of points, specifying optional parameters.

Parameters:
points - the points to construct the polygon.
strokeColor - The line color, a string that contains the color in hexadecimal numeric HTML style, i.e. #RRGGBB.
strokeWeight - The width of the line in pixels.
strokeOpacity - The opacity of the line - a value between 0.0 and 1.0.
fillColor - The fill color, a string that contains the color in hexadecimal numeric HTML style, i.e. #RRGGBB.
fillOpacity - The opacity of the fill - a value between 0.0 and 1.0.

Polygon

public Polygon(LatLng[] points,
               java.lang.String strokeColor,
               int strokeWeight,
               double strokeOpacity,
               java.lang.String fillColor,
               double fillOpacity,
               PolygonOptions options)
Create a polygon from an array of points, specifying optional parameters.

Parameters:
points - the points to construct the polygon.
strokeColor - The line color, a string that contains the color in hexadecimal numeric HTML style, i.e. #RRGGBB.
strokeWeight - The width of the line in pixels.
strokeOpacity - The opacity of the line - a value between 0.0 and 1.0.
fillColor - The fill color, a string that contains the color in hexadecimal numeric HTML style, i.e. #RRGGBB.
fillOpacity - The opacity of the fill - a value between 0.0 and 1.0.
options - additional options
Method Detail

fromEncoded

public static Polygon fromEncoded(EncodedPolyline[] polylines)
Create a polygon from an array of polylines. Overlapping regions of the polygons will be transparent.

Parameters:
polylines - array of polylines to use as the outline for the polygon.
Returns:
a new instance of Polygon.

fromEncoded

public static Polygon fromEncoded(EncodedPolyline[] polylines,
                                  boolean fill,
                                  java.lang.String color,
                                  double opacity,
                                  boolean outline)
Create a polygon from an array of polylines. Overlapping regions of the polygons will be transparent.

Parameters:
polylines - array of polylines to use as the outline for the polygon.
fill - whether to fill in the polygon with the specified color.
color - the color to use for the fill.
opacity - Opacity to use for the fill.
outline - true
Returns:
a new instance of Polygon.

addPolygonCancelLineHandler

public void addPolygonCancelLineHandler(PolygonCancelLineHandler handler)
This event is fired when the polygon is being edited and the edit is canceled. See setEditingEnabled(boolean)

Parameters:
handler - the handler to call when this event fires.

addPolygonClickHandler

public void addPolygonClickHandler(PolygonClickHandler handler)
This event is fired when the polygon is clicked. Note that this event also subsequently triggers a "click" event on the map, where the polygon is passed as the overlay argument within that event.

Parameters:
handler - the handler to call when this event fires.

addPolygonEndLineHandler

public void addPolygonEndLineHandler(PolygonEndLineHandler handler)
This event is fired when the polygon is being edited and the edit is completed. See setEditingEnabled(boolean)

Parameters:
handler - the handler to call when this event fires.

addPolygonLineUpdatedHandler

public void addPolygonLineUpdatedHandler(PolygonLineUpdatedHandler handler)
This event is fired when the polygon has a vertex inserted. See insertVertex(int,LatLng)

Parameters:
handler - the handler to call when this event fires.

addPolygonMouseOutHandler

public void addPolygonMouseOutHandler(PolygonMouseOutHandler handler)
This event is fired when the mouse moves out of a polygon.

Parameters:
handler - the handler to call when this event fires.

addPolygonMouseOverHandler

public void addPolygonMouseOverHandler(PolygonMouseOverHandler handler)
This event is fired when the mouse moves over a polygon.

Parameters:
handler - the handler to call when this event fires.

addPolygonRemoveHandler

public void addPolygonRemoveHandler(PolygonRemoveHandler handler)
This event is fired when the polygon is removed from the map, using MapWidget.removeOverlay(com.google.gwt.maps.client.overlay.Overlay) or MapWidget.clearOverlays().

Parameters:
handler - the handler to call when this event fires.

addPolygonVisibilityChangedHandler

public void addPolygonVisibilityChangedHandler(PolygonVisibilityChangedHandler handler)
This event is fired when the polygon is clicked. Note that this event also subsequently triggers a "click" event on the map, where the polygon is passed as the overlay argument within that event

Parameters:
handler - the handler to call when this event fires.

deleteVertex

public void deleteVertex(int index)
Removes with the given index in the polygon and updates the shape of the polygon accordingly. The Polygon must already be added to the map via MapWidget.addOverlay(Overlay).

Parameters:
index - the index of the vertex to remove.

getArea

public double getArea()
Returns the area (in square meters) of the polygon, assuming a spherical Earth.

Returns:
the area (in square meters) of the polygon, assuming a spherical Earth.

getBounds

public LatLngBounds getBounds()
Returns the bounds for this polygon.

Returns:
the bounds for this polygon.

getVertex

public LatLng getVertex(int index)
Returns the position of the specified vertex in the polygon.

Parameters:
index - the vertex to return.
Returns:
the position of the specified vertex in the polygon.

getVertexCount

public int getVertexCount()
Returns the number of vertices in the polygon.

Returns:
the number of vertices in the polygon.

isVisible

public boolean isVisible()
Returns true if the polygon is visible on the map.

Returns:
true if the polygon is visible on the map.

removePolygonCancelLineHandler

public void removePolygonCancelLineHandler(PolygonCancelLineHandler handler)
Removes a single handler of this map previously added with addPolygonCancelLineHandler(PolygonCancelLineHandler).

Parameters:
handler - the handler to remove

removePolygonClickHandler

public void removePolygonClickHandler(PolygonClickHandler handler)
Removes a single handler of this map previously added with addPolygonClickHandler(PolygonClickHandler).

Parameters:
handler - the handler to remove

removePolygonEndLineHandler

public void removePolygonEndLineHandler(PolygonEndLineHandler handler)
Removes a single handler of this map previously added with addPolygonEndLineHandler(PolygonEndLineHandler).

Parameters:
handler - the handler to remove

removePolygonLineUpdatedHandler

public void removePolygonLineUpdatedHandler(PolygonLineUpdatedHandler handler)
Removes a single handler of this map previously added with addPolygonLineUpdatedHandler(PolygonLineUpdatedHandler).

Parameters:
handler - the handler to remove

removePolygonMouseOutHandler

public void removePolygonMouseOutHandler(PolygonMouseOutHandler handler)
Removes a single handler of this map previously added with addPolygonMouseOutHandler(PolygonMouseOutHandler).

Parameters:
handler - the handler to remove

removePolygonMouseOverHandler

public void removePolygonMouseOverHandler(PolygonMouseOverHandler handler)
Removes a single handler of this map previously added with addPolygonMouseOverHandler(PolygonMouseOverHandler).

Parameters:
handler - the handler to remove

removePolygonRemoveHandler

public void removePolygonRemoveHandler(PolygonRemoveHandler handler)
Removes a single handler of this map previously added with addPolygonRemoveHandler(PolygonRemoveHandler).

Parameters:
handler - the handler to remove

removePolygonVisibilityChangedHandler

public void removePolygonVisibilityChangedHandler(PolygonVisibilityChangedHandler handler)
Removes a single handler of this map previously added with addPolygonVisibilityChangedHandler(PolygonVisibilityChangedHandler) .

Parameters:
handler - the handler to remove

setDrawingEnabled

public void setDrawingEnabled()
Allows a user to construct (or modify) a Polygon object by clicking on additional points on the map. The Polygon must already be added to the map via MapWidget.addOverlay(Overlay), even if the polygon is initially unpopulated and contains no vertices. Each click adds an additional vertex to the chain, and drawing may be terminated through either a double-click or clicking again on the last point added, at which point an PolygonEndLineHandler.PolygonEndLineEvent event will be triggered if the polygon was successfully completed; otherwise, a PolygonCancelLineHandler.PolygonCancelLineEvent event will be triggered, but the polygon will not be removed from the map. If modifying an existing Polygon, vertices are connected from either the starting or ending points of the existing polygon, specified in the optional {link PolyEditingOptions.setFromStart(boolean).


setDrawingEnabled

public void setDrawingEnabled(PolyEditingOptions opts)
Enable drawing as in setDrawingEnabled() but with control over the polygon drawing parameters.

Parameters:
opts - parameters for the polygon editing session.

setEditingEnabled

public void setEditingEnabled(boolean enabled)
Allows modification of an existing Polygon chain of points. When enabled, users may select and drag existing vertices. Unless a vertex limit less than current number of vertices is specified by PolyEditingOptions.setMaxVertices(int), "ghost" points will also be added at the midpoints of polyline sections, allowing users to interpolate new vertices by clicking and dragging these additional vertices. A PolygonLineUpdatedHandler.PolygonLineUpdatedEvent event will be triggered whenever vertex is added or moved. Note, you must add the polyline to the map before enabling editing.

Parameters:
enabled - true to turn on editing of this polyline.

setEditingEnabled

public void setEditingEnabled(PolyEditingOptions opts)
Enable editing as in setEditingEnabled(boolean), but with control over the drawing parameters. Note, you must add the polyline to the map before enabling editing.

Parameters:
opts - parameters for the editing session.

setFillStyle

public void setFillStyle(PolyStyleOptions style)
Changes the style of the polygon fill. The Polygon must already be added to the map via MapWidget.addOverlay(Overlay)

Parameters:
style - options for drawing the polygon fill.

setStrokeStyle

public void setStrokeStyle(PolyStyleOptions style)
Changes the style of the polylgon outline. The Polygon must already be added to the map via MapWidget.addOverlay(Overlay)

Parameters:
style - options for drawing the polygon outline.

setVisible

public void setVisible(boolean visible)
Show or hide the polygon.

Parameters:
visible - true to show the polygon.

supportsHide

public boolean supportsHide()
Returns true if this environment supports the setVisible(boolean) method.

Returns:
true if setVisible(false) is supported.