Documentation
Reference
2.1.55 (current version)
collection
interactivityModel
Interfaces

geometry.Polygon

Extends IPolygonGeometry.

The "Polygon" geometry.

See Polygon

Constructor | Fields | Events | Methods

Constructor

geometry.Polygon([coordinates[, fillRule[, options]]])

Parameters:

ParameterDefault valueDescription
coordinates []

Type: Number[][][]

Geometry coordinates. A three-dimensional array of elements that are each two-dimensional coordinates of the polygon contours. The first element describes the outer contour, and the rest describe the inner contours.

fillRule "evenOdd"

Type: String

String ID that defines the polygon fill rule. Accepts one of two values:

  • evenOdd - Algorithm that checks whether a point is located in the fill area by drawing a ray from this point to infinity in any direction, and counting the number of contour segments in this shape that are crossed by this ray. If the number is odd, the point is inside it; if even, the point is outside it.
  • nonZero - Algorithm that checks whether a point is located in the fill area by drawing a ray from this point to infinity in any direction, and checking the points at which a segment of the shape crosses this ray. Starting from zero, one is added each time a segment crosses the ray from left to right, and one is subtracted each time a segment crosses the ray from right to left. If the result equals zero, the point is inside the contour. Otherwise, it is outside it.

options

Type: Object

Geometry options.

options.coordRendering "shortestPath"

Type: String

String ID defining the algorithm for recalculating geometry coordinates as pixel coordinates. Accepts one of two values:

  • shortestPath - Algorithm that considers projection cycling on the axes and generates pixel coordinates so that the distance between two neighboring points is minimal.
  • straightPath - Algorithm that does not consider projection cycling.

options.geodesic false

Type: Boolean

Enables display using geodesic lines.

options.pixelRendering "jumpy"

Type: String

Method for calculating pixel coordinates of the shape in cycled projections. This option accepts one of the following values:

  • jumpy - The shape is placed as close as possible to the center of the map viewport, and can "jump" when the map is being moved.
  • static - The shape is always located in the initial world and does not move when the map is moved.

options.projection

Type: IProjection

Projection.

options.simplification true

Type: Boolean

Enables simplification during rendering of a pixel geometry.

Example:

// Creating an instance of the polygon geometry (specifying coordinates of vertexes on contours).
var polygonGeometry = new ymaps.geometry.Polygon([
    // Outer contour.
    [
        [0, 0], [0, 5], [5, 5], [5, 0], [0, 0]
    ],
    // Inner contour.
    [
        [1, 1], [1, 2], [2, 2], [2, 1], [1, 1]
    ]
]),
// Creating a geo object instance and passing our geometry to the constructor.
    polygonGeoObject = new ymaps.GeoObject({ geometry: polygonGeometry });

// You can also access polygonGeometry via polygonGeoObject.geometry.

Fields

NameTypeDescription
eventsIEventManager

Event manager.

Inherited from IEventEmitter.

optionsIOptionManager

Options manager.

Inherited from ICustomizable.

Events

NameDescription
change

Changed coordinates. Instance of the Event class. Names of fields that are available via the Event#get method:

  • oldCoordinates - Old coordinates
  • newCoordinates - New coordinates.
  • oldFillRule - Old fill rule.
  • newFillRule - New fill rule.

Inherited from IPolygonGeometryAccess.

mapchange

Map reference changed. Instance of the Event class. Names of fields that are available via the Event#get method:

  • oldMap - Old map.
  • newMap - New map.

Inherited from IGeometry.

optionschange

Change to the object options.

Inherited from ICustomizable.

pixelgeometrychange

The pixel geometry changed. Instance of the Event class. Names of fields that are available via the Event#get method:

Inherited from IGeometry.

Methods

NameReturnsDescription
contains(position)

Boolean

Checks whether the passed point is located inside the polygon.

Inherited from IPolygonGeometryAccess.

freeze()

IFreezable

Switches the object to "frozen" mode.

Inherited from IFreezable.

get(index)

Number[][]

Returns coordinates of the contour with the specified index.

Inherited from IPolygonGeometryAccess.

getBounds()

Number[][]|null

Returns coordinates of the two opposite corners of the area that surrounds the geometry. The first item in the array is the southwest corner of the area; the second item is the northeast corner.

Inherited from IGeometry.

getChildGeometry(index)

ILinearRingGeometryAccess

Creates and returns an ILinearRingGeometryAccess object for the specified contour.

Inherited from IPolygonGeometryAccess.

getClosest(anchorPosition)

Object

Searches for the point nearest to "anchorPosition" on the polygon contour.

Inherited from IPolygonGeometryAccess.

getCoordinates()

Number[][][]

Returns an array of geometry coordinates.

Inherited from IPolygonGeometryAccess.

getFillRule()

String

Returns ID of the fill rule.

Inherited from IPolygonGeometryAccess.

getLength()

Integer

Returns the number of contours in the geometry.

Inherited from IPolygonGeometryAccess.

getMap()

Map|null

Returns the current map.

Inherited from IGeometry.

getPixelGeometry([options])

IPixelGeometry

Returns the pixel geometry corresponding to the given geometry, its options, and the map state.

Inherited from IGeometry.

getType()

String

Returns the "Polygon" string.

Inherited from IPolygonGeometry.

insert(index, path)

IPolygonGeometryAccess

Adds a new contour with the specified index.

Inherited from IPolygonGeometryAccess.

isFrozen()

Boolean

Returns true if the object is in "frozen" mode, otherwise false.

Inherited from IFreezable.

remove(index)

ILinearRingGeometryAccess

Removes the contour with the specified index.

Inherited from IPolygonGeometryAccess.

set(index, path)

IPolygonGeometryAccess

Sets coordinates of the contour with the specified index.

Inherited from IPolygonGeometryAccess.

setCoordinates(coordinates)

IPolygonGeometryAccess

Sets an array of geometry coordinates.

Inherited from IPolygonGeometryAccess.

setFillRule(fillRule)

IPolygonGeometryAccess

Sets the polygon's fill rule.

Inherited from IPolygonGeometryAccess.

setMap(map)

Sets the map.

Inherited from IGeometry.

splice(index, number)

ILinearRingGeometryAccess[]

Deletes a defined number of contours, starting from the specified index. New contours can be added in place of the deleted ones. Coordinates of the new contours can be passed as additional arguments after the "number" parameter.

Inherited from IPolygonGeometryAccess.

unfreeze()

IFreezable

Switches the object to active mode.

Inherited from IFreezable.