public class

Polygon

extends Overlay
java.lang.Object
   ↳ com.neomades.maps.overlay.BaseOverlay
     ↳ com.neomades.maps.overlay.Overlay
       ↳ com.neomades.maps.overlay.Polygon

Class Overview

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:

Outline

The outline is specified by a list of vertices in clockwise or counterclockwise order. It is not necessary for the start and end points to coincide; if they do not, the polygon will be automatically closed. Line segments are drawn between consecutive points in the shorter of the two directions (east or west).

Holes

A hole is a region inside the polygon that is not filled. A hole is specified in exactly the same way as the outline. A hole must be fully contained within the outline. Multiple holes can be specified, however overlapping holes are not supported.

Stroke Width

Line segment width in screen pixels. The width is constant and independent of the camera's zoom level. The default value is 10.

Stroke Color

Line segment color in ARGB format, the same format used by Color. The default value is black (0xff000000).

Fill Color

Fill color in ARGB format, the same format used by 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.

Z-Index

The order in which this polygon is drawn with respect to other overlays, including Polylines and Circles 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.

Visibility

Indicates if the polygon is visible or invisible, i.e., whether it is drawn on the map. An invisible polygon is not drawn, but retains all of its other properties. The default is true, i.e., visible.

Geodesic status

Indicates whether the segments of the polygon should be drawn as geodesics, as opposed to straight lines on the Mercator projection. A geodesic is the shortest path between two points on the Earth's surface. The geodesic curve is constructed assuming the Earth is a sphere.

Methods that modify a Polygon must be called on the main thread. If not, an IllegalStateException will be thrown at runtime.

Example
 Map map;
 // ... get a map.
 // Add a triangle in the Gulf of Guinea
 Vector points = new Vector();
 points.add(new Location(0, 0));
 points.add(new Location(0, 5));
 points.add(new Location(3, 5));
 points.add(new Location(0, 0));
 map.add(new Polygon().setPoints(points).setStrokeColor(Color.RED).setFillColor(Color.BLUE));
 

Summary

Public Constructors
Polygon()
Public Methods
Color getFillColor()
Gets the fill color of this polygon.
Vector getHoles()
Returns a snapshot of the holes of this polygon at this time.
Vector getPoints()
Returns a snapshot of the vertices of this polygon at this time .
Color getStrokeColor()
Gets the stroke color of this polygon.
int getStrokeWidth()
Gets the stroke width of this polygon.
boolean isGeodesic()
Gets whether each segment of the line is drawn as a geodesic or not.
Polygon setFillColor(Color color)
Sets the fill color of this polygon.
Polygon setGeodesic(boolean geodesic)
Sets whether to draw each segment of the line as a geodesic or not.
Polygon setHoles(Vector holes)
Sets the holes of this polygon.
Polygon setPoints(Vector points)
Sets the points of this polygon.
Polygon setStrokeColor(Color color)
Sets the stroke color of this polygon.
Polygon setStrokeWidth(int width)
Sets the stroke width of this polygon.
Polygon setVisible(boolean visible)
Sets the visibility of this polygon.
Polygon setZIndex(int zIndex)
Sets the z-index of this polygon.
[Expand]
Inherited Methods
From class com.neomades.maps.overlay.Overlay
From class com.neomades.maps.overlay.BaseOverlay
From class java.lang.Object

Public Constructors

public Polygon ()

Public Methods

public Color getFillColor ()

Gets the fill color of this polygon.

Returns
  • the color in ARGB format.

public Vector getHoles ()

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. To change the holes of the polygon, call setHoles(Vector).

Returns
  • copy of the list of holes

public Vector getPoints ()

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(Vector).

Returns
  • copy of the list of vertices

public Color getStrokeColor ()

Gets the stroke color of this polygon.

Returns
  • the color in ARGB format.

public int getStrokeWidth ()

Gets the stroke width of this polygon.

Returns
  • the width in screen pixels.

public boolean isGeodesic ()

Gets whether each segment of the line is drawn as a geodesic or not.

Cross Platform considerations

Supported only on the Android platform. Returns false for other platforms.

Returns
  • true if each segment is drawn as a geodesic; false if each segment is drawn as a straight line on the Mercator projection.

public Polygon setFillColor (Color color)

Sets the fill color of this polygon.

Parameters
color the color in ARGB format

public Polygon setGeodesic (boolean geodesic)

Sets whether to draw each segment of the line as a geodesic or not.

Cross Platform considerations

Supported only on the Android platform.

Parameters
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.

public Polygon setHoles (Vector holes)

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.

Parameters
holes a list of holes, where a hole is a list of Location.

public Polygon setPoints (Vector points)

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.

Parameters
points a list of Location that are the vertices of the polygon.

public Polygon setStrokeColor (Color color)

Sets the stroke color of this polygon.

Parameters
color the color in ARGB format

public Polygon setStrokeWidth (int width)

Sets the stroke width of this polygon.

Cross Platform considerations

The default stroke width may vary among the different platforms.

Parameters
width the width in display pixels.

public Polygon setVisible (boolean visible)

Sets the visibility of this polygon. When not visible, a polygon is not drawn, but it keeps all its other properties.

Parameters
visible if true, then the polygon is visible; if false, it is not.

public Polygon setZIndex (int zIndex)

Sets the z-index of this polygon. Polygons with higher zIndices are drawn above those with lower indices.

Parameters
zIndex the z-index of this polygon.