ILineStringGeometryAccess

Extends IFreezable.

Interface for access to the "Polyline" geometry.

Constructor | Fields | Events | Methods

Constructor

ILineStringGeometryAccess()

Fields

Name

Type

Description

events

IEventManager

Event manager for the object.

Inherited from IFreezable.

Events

Name

Description

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.

Methods

Name

Returns

Description

freeze()

IFreezable

Switches the object to "frozen" mode.

Inherited from IFreezable.

get(index)

Number[]

Returns coordinates of the point with the specified index.

getChildGeometry(index)

IPointGeometryAccess

Creates and returns an IPointGeometryAccess object for the specified vertex on the polyline.

getClosest(anchorPosition)

Object

Searches for a point on the polyline closest to the anchorPosition.

getCoordinates()

Number[][]

Returns an array of geometry coordinates.

getLength()

Integer

Returns the number of points in the geometry.

insert(index, coordinates)

ILineStringGeometryAccess

Adds a new point with the specified index.

isFrozen()

Boolean

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

Inherited from IFreezable.

remove(index)

Number[]

Removes the point with the specified index.

set(index, coordinates)

ILineStringGeometryAccess

Sets coordinates of the point with the specified index.

setCoordinates(coordinates)

ILineStringGeometryAccess

Sets an array of geometry coordinates.

splice(index, number)

Number[][]

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

unfreeze()

IFreezable

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.

Methods details

get

{Number[]} get(index)

Returns coordinates of the point with the specified index.

Parameters:

Parameter

Default value

Description

index*

—

Type: Integer

Index of a point.

* Mandatory parameter/option.

Example:

// Marking the start of the line with a placemark:
map.geoObjects.add(
    new ymaps.Placemark(polyline.geometry.get(0), { iconContent: 'A' })
);

getChildGeometry

{IPointGeometryAccess} getChildGeometry(index)

Creates and returns an IPointGeometryAccess object for the specified vertex on the polyline.

Returns the "Point" geometry object that corresponds to the specified endpoint.

Parameters:

Parameter

Default value

Description

index*

—

Type: Integer

Index of an endpoint.

* Mandatory parameter/option.

getClosest

{Object} getClosest(anchorPosition)

Searches for a point on the polyline closest to the anchorPosition.

Returns an object with the following fields:

  • position - Point on the polyline closest to "anchorPosition".
  • distance - Distance from "anchorPosition" to "position".
  • closestPointIndex - Index of the vertex closest to "position".
  • nextPointIndex - Index of the vertex that follows "position".
  • prevPointIndex - Index of the vertex that precedes "position".
    The "nextPointIndex" and "prevPointIndex" fields may be omitted if "position" coincides with one of the polyline vertexes.

Parameters:

Parameter

Default value

Description

anchorPosition*

—

Type: Number[]

Coordinates of a point for which the nearest polyline vertex is calculated.

* Mandatory parameter/option.

Example:

// Deleting points from the line when clicked:
myPolyline.events.add('click', function (e) {
    myPolyline.geometry.remove(
        myPolyline.geometry.getClosest(e.get('coords')).closestPointIndex
    );
});

getCoordinates

{Number[][]} getCoordinates()

Returns an array of geometry coordinates.

getLength

{Integer} getLength()

Returns the number of points in the geometry.

insert

{ILineStringGeometryAccess} insert(index, coordinates)

Adds a new point with the specified index.

Returns self-reference.

Parameters:

Parameter

Default value

Description

index*

—

Type: Integer

Index of a point.

coordinates*

—

Type: Number[]

Coordinates of a point.

* Mandatory parameter/option.

Example:

// Adding a new point to the end of the line when the map is clicked.
myMap.events.add('click', function (e) {
    myLineString.insert(myLineString.getLength(), e.get('coords'))
});

remove

{Number[]} remove(index)

Removes the point with the specified index.

Returns the coordinates of a deleted point.

Parameters:

Parameter

Default value

Description

index*

—

Type: Integer

Index of a point.

* Mandatory parameter/option.

set

{ILineStringGeometryAccess} set(index, coordinates)

Sets coordinates of the point with the specified index.

Returns self-reference.

Parameters:

Parameter

Default value

Description

index*

—

Type: Integer

Index of a point.

coordinates*

—

Type: Number[]

Coordinates of a point.

* Mandatory parameter/option.

setCoordinates

{ILineStringGeometryAccess} setCoordinates(coordinates)

Sets an array of geometry coordinates.

Returns self-reference.

Parameters:

Parameter

Default value

Description

coordinates*

—

Type: Number[][]

Geometry coordinates.

* Mandatory parameter/option.

splice

{Number[][]} splice(index, number)

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

Returns an array of coordinates of deleted points.

Parameters:

Parameter

Default value

Description

index*

—

Type: Integer

The index to start from for removing and adding points.

number*

—

Type: Integer

The number of deleted points.

* Mandatory parameter/option.

Example:

// Adding a new point to the start of the line when the map is clicked.
myMap.events.add('click', function (e) {
    myLineString.splice(0, 0, myLineString.getLength(), e.get('coords'))
});