IPolygonGeometryAccess
Extends IFreezable.
Interface for accessing the "Polygon" geometry.
Constructor | Fields | Events | Methods
Constructor
IPolygonGeometryAccess()
Fields
Name |
Type |
Description |
Event manager for the object. Inherited from IFreezable. |
Events
Name |
Description |
Changed coordinates. Instance of the Event class. Names of fields that are available via the Event.get method:
|
Methods
Name |
Returns |
Description |
Boolean |
Checks whether the passed point is located inside the polygon. |
|
freeze() |
Switches the object to "frozen" mode. Inherited from IFreezable. |
|
Number[][] |
Returns coordinates of the contour with the specified index. |
|
Creates and returns an ILinearRingGeometryAccess object for the specified contour. |
||
Object |
Searches for the point nearest to "anchorPosition" on the polygon contour. |
|
Number[][][] |
Returns an array of geometry coordinates. |
|
String |
Returns ID of the fill rule. |
|
Integer |
Returns the number of contours in the geometry. |
|
Adds a new contour with the specified index. |
||
isFrozen() |
Boolean |
Returns true if the object is in "frozen" mode, otherwise false. Inherited from IFreezable. |
Removes the contour with the specified index. |
||
Sets coordinates of the contour with the specified index. |
||
Sets an array of geometry coordinates. |
||
Sets the polygon's fill rule. |
||
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. |
||
unfreeze() |
Switches the object to active mode. Inherited from IFreezable. |
Events details
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.
Methods details
contains
{Boolean} contains(position)
Checks whether the passed point is located inside the polygon.
Returns indicator for whether the point belongs to the polygon.
Parameters:
Parameter |
Default value |
Description |
— |
Type: Number[] Coordinates of a point. |
* Mandatory parameter/option.
Example:
var myPolygon = new ymaps.geometry.Polygon([
[[69, 45], [68, 55], [86, 56]]
]);
// This method only works with a map that is set correctly.
myPolygon.options.setParent(myMap.options);
myPolygon.geometry.setMap(myMap);
// Checking whether the click point is inside the polygon with the geometry set above.
myMap.events.add('click', function (e) {
alert(myPolygon.geometry.contains(e.get('coords')) ? 'Hit!' : 'Miss!');
});
get
{Number[][]} get(index)
Returns coordinates of the contour with the specified index.
Parameters:
Parameter |
Default value |
Description |
— |
Type: Integer Contour index. |
* Mandatory parameter/option.
getChildGeometry
{ILinearRingGeometryAccess} getChildGeometry(index)
Creates and returns an ILinearRingGeometryAccess object for the specified contour.
Returns the geometry object that corresponds to the specified contour.
Parameters:
Parameter |
Default value |
Description |
— |
Type: Integer Contour index. |
* Mandatory parameter/option.
getClosest
{Object} getClosest(anchorPosition)
Searches for the point nearest to "anchorPosition" on the polygon contour.
Returns an object with the following fields:
- position - The point on the polygon contour that is nearest to "anchorPosition".
- distance - Distance from "anchorPosition" to "position".
- closestPointIndex - Index of the polygon vertex closest to "position".
- nextPointIndex - Index of the polygon vertex that follows "position".
- prevPointIndex - Index of the polygon vertex that precedes "position".
- pathIndex - Index of the polygon contour that the found point is associated with.
The "nextPointIndex" and "prevPointIndex" fields may be omitted if "position" coincides with one of the polygon vertexes.
Parameters:
Parameter |
Default value |
Description |
— |
Type: Number[] Coordinates of a point for which the nearest vertex on the polygon contour is calculated. |
* Mandatory parameter/option.
Example:
var myPolygon = new ymaps.Polygon([
[[69, 45], [68, 55], [86, 56], [87, 43]],
[[60, 48], [62, 60], [80, 62], [80, 48]]
]);
var myPoint = new ymaps.Placemark([74, 52]);
// Constructing the shortest normal from the polygon contour to the point.
var normalVec = new ymaps.Polyline([
myPolygon.geometry.getClosest(myPoint.geometry.getCoordinates()).position,
myPoint.geometry.getCoordinates()
]);
myMap.geoObjects
.add(myPolygon)
.add(myPoint)
.add(normalVec);
getCoordinates
{Number[][][]} getCoordinates()
Returns an array of geometry coordinates.
getFillRule
{String} getFillRule()
Returns ID of the fill rule.
Example:
var myPolygon = new ymaps.Polygon([
[[69, 45], [68, 55], [86, 56], [87, 43]],
[[60, 48], [62, 60], [80, 62], [80, 48]]
]);
var middlePoint = [74, 52];
myMap.geoObjects.add(myPolygon);
// Checking a point that falls on the intersection of two contours
// by default (with the value fillRule == 'evenOdd') forms an opening (hole).
alert(myPolygon.geometry.contains(middlePoint)); // => false
// After setting the value to 'nonZero', all intersections are also "filled in",
// so now the point is in the polygon.
myPolygon.geometry.setFillRule('nonZero');
alert(myPolygon.geometry.contains(middlePoint)); // => true
getLength
{Integer} getLength()
Returns the number of contours in the geometry.
insert
{IPolygonGeometryAccess} insert(index, path)
Adds a new contour with the specified index.
Returns self-reference.
Parameters:
Parameter |
Default value |
Description |
— |
Type: Integer Contour index. |
|
|
— |
Type: Number[][] Contour coordinates. |
* Mandatory parameter/option.
remove
{ILinearRingGeometryAccess} remove(index)
Removes the contour with the specified index.
Returns the deleted contour.
Parameters:
Parameter |
Default value |
Description |
— |
Type: Integer Contour index. |
* Mandatory parameter/option.
set
{IPolygonGeometryAccess} set(index, path)
Sets coordinates of the contour with the specified index.
Returns self-reference.
Parameters:
Parameter |
Default value |
Description |
— |
Type: Integer Contour index. |
|
|
— |
Type: Number[][] Contour coordinates. |
* Mandatory parameter/option.
setCoordinates
{IPolygonGeometryAccess} setCoordinates(coordinates)
Sets an array of geometry coordinates.
Returns self-reference.
Parameters:
Parameter |
Default value |
Description |
— |
Type: Number[][][] Geometry coordinates. |
* Mandatory parameter/option.
setFillRule
{IPolygonGeometryAccess} setFillRule(fillRule)
Sets the polygon's fill rule.
Returns self-reference.
Parameters:
Parameter |
Default value |
Description |
— |
Type: String ID of the fill rule. |
* Mandatory parameter/option.
splice
{ILinearRingGeometryAccess[]} splice(index, number)
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.
Returns the deleted contours.
Parameters:
Parameter |
Default value |
Description |
— |
Type: Integer The index to start from for removing and adding contours. |
|
— |
Type: Integer The number of contours to be deleted. |
* Mandatory parameter/option.
Mandatory parameter/option.