google-maps-documentation

Polygon class

google.maps.Polygon class

A polygon (like a polyline) defines a series of connected coordinates in an ordered sequence. Additionally, polygons form a closed loop and define a filled region. See the samples in the developer's guide, starting with a simple polygon, a polygon with a hole, and more. Note that you can also use the Data layer to create a polygon. The Data layer offers a simpler way of creating holes because it handles the order of the inner and outer paths for you.

This class extends MVCObject.

Constructor
Polygon
Polygon([opts])
Parameters: 
Create a polygon using the passed PolygonOptions, which specify the polygon's path, the stroke style for the polygon's edges, and the fill style for the polygon's interior regions. A polygon may contain one or more paths, where each path consists of an array of LatLngs. You may pass either an array of LatLngs or an MVCArray of LatLngs when constructing these paths. Arrays are converted to MVCArrays within the polygon upon instantiation.
Methods
getDraggable
getDraggable()
Parameters:  None
Return Value:  boolean
Returns whether this shape can be dragged by the user.
getEditable
getEditable()
Parameters:  None
Return Value:  boolean
Returns whether this shape can be edited by the user.
getMap
getMap()
Parameters:  None
Return Value:  Map
Returns the map on which this shape is attached.
getPath
getPath()
Parameters:  None
Return Value:  MVCArray<LatLng>
Retrieves the first path.
getPaths
getPaths()
Parameters:  None
Return Value:  MVCArray<MVCArray<LatLng>>
Retrieves the paths for this polygon.
getVisible
getVisible()
Parameters:  None
Return Value:  boolean
Returns whether this poly is visible on the map.
setDraggable
setDraggable(draggable)
Parameters: 
  • draggableboolean
Return Value:  None
If set to true, the user can drag this shape over the map. The geodesic property defines the mode of dragging.
setEditable
setEditable(editable)
Parameters: 
  • editableboolean
Return Value:  None
If set to true, the user can edit this shape by dragging the control points shown at the vertices and on each segment.
setMap
setMap(map)
Parameters: 
Return Value:  None
Renders this shape on the specified map. If map is set to null, the shape will be removed.
setOptions
setOptions(options)
Parameters: 
Return Value:  None
setPath
setPath(path)
Parameters: 
Return Value:  None
Sets the first path. See PolygonOptions for more details.
setPaths
setPaths(paths)
Parameters: 
Return Value:  None
Sets the path for this polygon.
setVisible
setVisible(visible)
Parameters: 
  • visibleboolean
Return Value:  None
Hides this poly if set to false.
Events
click
function(event)
Arguments: 
This event is fired when the DOM click event is fired on the Polygon.
dblclick
function(event)
Arguments: 
This event is fired when the DOM dblclick event is fired on the Polygon.
drag
function(event)
Arguments: 
This event is repeatedly fired while the user drags the polygon.
dragend
function(event)
Arguments: 
This event is fired when the user stops dragging the polygon.
dragstart
function(event)
Arguments: 
This event is fired when the user starts dragging the polygon.
mousedown
function(event)
Arguments: 
This event is fired when the DOM mousedown event is fired on the Polygon.
mousemove
function(event)
Arguments: 
This event is fired when the DOM mousemove event is fired on the Polygon.
mouseout
function(event)
Arguments: 
This event is fired on Polygon mouseout.
mouseover
function(event)
Arguments: 
This event is fired on Polygon mouseover.
mouseup
function(event)
Arguments: 
This event is fired when the DOM mouseup event is fired on the Polygon.
rightclick
function(event)
Arguments: 
This event is fired when the Polygon is right-clicked on.