geometry.Rectangle

Extends IRectangleGeometry.

The "Rectangle" geometry.

See Rectangle

Constructor | Fields | Events | Methods

Constructor

geometry.Rectangle([coordinates[, options]])

Parameters:

Parameter

Default value

Description

coordinates

null

Type: Number[][]|null

An array containing coordinates of two opposite corners of the rectangle.

options

Type: Object

Geometry options.

options.coordRendering

Type: String

String ID defining the algorithm for recalculating geometry coordinates as pixel coordinates. For the "Rectangle" geometry, can accept one of three values:

  • shortestPath - Algorithm that considers projection cycling on the axes and generates pixel coordinates so that the distance between opposite corners is minimal.
  • straightPath - Algorithm that does not consider projection cycling.
  • boundsPath - Algorithm that interprets the coordinates of rectangle corners as coordinates corresponding to the lower and upper corners of a bounding area. When calculating diagonals for projections with cycled axes, the counter-clockwise direction is always used.

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.

Example:

// Creating an instance of the point geometry (specifying coordinates).
var rectangleGeometry = new ymaps.geometry.Rectangle([[30, 50], [31, 51]]);
// Instantiating the geo object and passing our geometry to the constructor.
var rectangleGeoObject = new ymaps.GeoObject({ geometry: rectangleGeometry });

// Changing the coordinates via the geo object's "geometry" property.
rectangleGeoObject.geometry.setCoordinates([[10, 20], [51, 71]]);
// Or directly.
rectangleGeometry.setCoordinates([[10, 20], [51, 71]]);
// You can also access rectangleGeometry via rectangleGeoObject.geometry.

Fields

Name

Type

Description

events

IEventManager

Event manager.

Inherited from IEventEmitter.

options

IOptionManager

Options manager.

Inherited from ICustomizable.

Events

Name

Description

change

Change to corner coordinates. Instance of the Event class. Names of fields that are available via the Event.get method:

  • oldCoordinates - Old coordinates of the corners.
  • newCoordinates - New coordinates of the corners.

Inherited from IRectangleGeometryAccess.

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

Name

Returns

Description

contains(position)

Boolean

Checks whether the passed point is located inside the rectangle.

Inherited from IRectangleGeometryAccess.

freeze()

IFreezable

Switches the object to "frozen" mode.

Inherited from IFreezable.

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.

getClosest(anchorPosition)

Object

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

Inherited from IRectangleGeometryAccess.

getCoordinates()

Number[][]

Returns coordinates of two opposite corners of the rectangle.

Inherited from IRectangleGeometryAccess.

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 "Rectangle" string.

Inherited from IRectangleGeometry.

isFrozen()

Boolean

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

Inherited from IFreezable.

setCoordinates(coordinates)

IRectangleGeometryAccess

Sets the coordinates of two opposite corners of the rectangle.

Inherited from IRectangleGeometryAccess.

setMap(map)

Sets the map.

Inherited from IGeometry.

unfreeze()

IFreezable

Switches the object to active mode.

Inherited from IFreezable.