A polygon on the earth's surface. A polygon can be convex or concave, it may span the 180 meridian and it can have holes that are not filled in. It has the following properties:
Color. The
default value is black (0xff000000).JointType
for supported joint types. The default value is JointType.DEFAULT.null) or a sequence of PatternItem
objects to be repeated along the polygon's outline. Available PatternItem
types: Gap (defined by
gap length in pixels), Dash (defined
by stroke width and dash length in pixels) and Dot (circular,
centered on the polygon's outline, diameter defined by stroke width in pixels).Color. The
default value is transparent (0x00000000). If the polygon geometry is not
specified correctly (see above for Outline and Holes), then no fill will be drawn.Polylines,
Circles,
GroundOverlays
and TileOverlays,
but not Markers. An
overlay with a larger z-index is drawn over overlays with smaller z-indices. The order of
overlays with the same z-index value is arbitrary. The default is 0.true, i.e., visible.true. You can change this value at any time. The default is
false. If this property is set to true, your app will receive
notifications to the GoogleMap.OnPolygonClickListener
registered through
GoogleMap.setOnPolygonClickListener(GoogleMap.OnPolygonClickListener).Object associated with the polygon. For example, the
Object can contain data about what the polygon represents. This is easier than
storing a separate Map<Polygon, Object>. As another example, you can
associate a String ID corresponding to the ID from a data set. Google Maps SDK
for Android neither reads nor writes this property.Methods in this class must be called on the Android UI thread. If not, an IllegalStateException
will be thrown at runtime.
GoogleMap map;
// ... get a map.
// Add a triangle in the Gulf of Guinea
Polygon polygon = map.addPolygon(new PolygonOptions()
.add(new LatLng(0, 0), new LatLng(0, 5), new LatLng(3, 5), new LatLng(0, 0))
.strokeColor(Color.RED)
.fillColor(Color.BLUE));
For more information, read the Shapes developer guide.
| boolean | |
| int |
getFillColor()
Gets the fill color of this polygon.
|
| List<List<LatLng>> |
getHoles()
Returns a snapshot of the holes of this polygon at this time .
|
| String |
getId()
Gets this polygon's id.
|
| List<LatLng> |
getPoints()
Returns a snapshot of the vertices of this polygon at this time .
|
| int |
getStrokeColor()
Gets the stroke color of this polygon.
|
| int |
getStrokeJointType()
Gets the stroke joint type used at all vertices of the polygon's outline.
|
| List<PatternItem> |
getStrokePattern()
Gets the stroke pattern of this polygon's outline.
|
| float |
getStrokeWidth()
Gets the stroke width of this polygon.
|
| Object |
getTag()
Gets the tag for the polygon.
|
| float |
getZIndex()
Gets the zIndex of this polygon.
|
| int |
hashCode()
|
| boolean |
isClickable()
Gets the clickability of the polygon.
|
| boolean |
isGeodesic()
Gets whether each segment of the line is drawn as a geodesic or not.
|
| boolean |
isVisible()
Gets the visibility of this polygon.
|
| void |
remove()
Removes the polygon from the map.
|
| void |
setClickable(boolean clickable)
Sets the clickability of the polygon.
|
| void |
setFillColor(int color)
Sets the fill color of this polygon.
|
| void |
setGeodesic(boolean geodesic)
Sets whether to draw each segment of the line as a geodesic or not.
|
| void | |
| void | |
| void |
setStrokeColor(int color)
Sets the stroke color of this polygon.
|
| void |
setStrokeJointType(int jointType)
Sets the joint type for all vertices of the polygon's outline.
|
| void | |
| void |
setStrokeWidth(float width)
Sets the stroke width of this polygon.
|
| void | |
| void |
setVisible(boolean visible)
Sets the visibility of this polygon.
|
| void |
setZIndex(float zIndex)
Sets the zIndex of this polygon.
|
Gets the fill color of this polygon.
Returns a snapshot of the holes of this polygon at this time . The list returned is a copy of the list of holes and so changes to the polygon's holes will not be reflected by this list, nor will changes to this list be reflected by the polygon.
Gets this polygon's id. The id will be unique amongst all Polygons on a map.
Returns a snapshot of the vertices of this polygon at this time . The list returned
is a copy of the list of vertices and so changes to the polygon's vertices will not be
reflected by this list, nor will changes to this list be reflected by the polygon. To
change the vertices of the polygon, call
setPoints(List).
Gets the stroke color of this polygon.
Gets the stroke joint type used at all vertices of the polygon's outline. See
JointType
for possible values.
Gets the stroke pattern of this polygon's outline.
null if default pattern is used.Gets the stroke width of this polygon.
Gets the tag for the polygon.
setTag(Object); null if no tag has been set.Gets the zIndex of this polygon.
Gets the clickability of the polygon. If the polygon is clickable, your app will
receive notifications to the GoogleMap.OnPolygonClickListener
when the user clicks the polygon. The event listener is registered through
GoogleMap.setOnPolygonClickListener(GoogleMap.OnPolygonClickListener).
true if the polygon is clickable; otherwise, returns
false.Gets whether each segment of the line is drawn as a geodesic or not.
true if each segment is drawn as a geodesic; false if
each segment is drawn as a straight line on the Mercator projection.Gets the visibility of this polygon.
Removes the polygon from the map. After a polygon has been removed, the behavior of all its methods is undefined.
Sets the clickability of the polygon. If the polygon is clickable, your app will
receive notifications to the GoogleMap.OnPolygonClickListener
when the user clicks the polygon. The event listener is registered through
GoogleMap.setOnPolygonClickListener(GoogleMap.OnPolygonClickListener).
| clickable | New clickability setting for the polygon. |
|---|
Sets the fill color of this polygon.
| color | the color in ARGB format |
|---|
Sets whether to draw each segment of the line as a geodesic or not.
| geodesic | if true, then each segment is drawn as a geodesic; if
false, each segment is drawn as a straight line on the Mercator
projection. |
|---|
Sets the holes of this polygon. This method will take a copy of the holes, so
further mutations to holes will have no effect on this polygon.
| holes | an list of holes, where a hole is an list of LatLngs. |
|---|
Sets the points of this polygon. This method will take a copy of the points, so
further mutations to points will have no effect on this polygon.
| points | a list of LatLngs
that are the vertices of the polygon. Must not be null. |
|---|
Sets the stroke color of this polygon.
| color | the color in ARGB format |
|---|
Sets the joint type for all vertices of the polygon's outline.
See JointType
for allowed values. The default value JointType.DEFAULT
will be used if joint type is undefined or is not one of the allowed values.
| jointType | the stroke joint type. |
|---|
Sets the stroke pattern of the polygon's outline. The default stroke pattern is
solid, represented by null.
| pattern | the stroke pattern. |
|---|
Sets the stroke width of this polygon.
| width | the width in display pixels. |
|---|
Sets the tag for the polygon.
You can use this property to associate an arbitrary Object with this
polygon. For example, the Object can contain data about what the polygon
represents. This is easier than storing a separate Map<Polygon,
Object>. As another example, you can associate a String ID
corresponding to the ID from a data set. Google Maps SDK for Android neither reads nor
writes this property. It is your responsibility to call setTag(null) to
clear the tag when you no longer need it, to prevent memory leaks in your app.
| tag | if null, the tag is cleared. |
|---|
Sets the visibility of this polygon. When not visible, a polygon is not drawn, but it keeps all its other properties.
| visible | if true, then the polygon is visible; if false, it is
not. |
|---|
Sets the zIndex of this polygon. Polygons with higher zIndices are drawn above those with lower indices.
| zIndex | the zIndex of this polygon. |
|---|