Documentation
Reference
2.1.56 (current version)
collection
interactivityModel
Interfaces

geometry.LineString

Extends ILineStringGeometry.

"Polyline" geometry.

See Polyline

Constructor | Fields | Events | Methods

Constructor

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

Parameters:

ParameterDefault valueDescription
coordinates []

Type: Number[][]

Geometry coordinates.

options

Type: Object

Geometry options.

options.coordRendering

Type: String

String ID defining the algorithm for recalculating geometry coordinates as pixel coordinates. For the "Polyline" geometry, can accept 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:

// Instantiates the point geometry (specifying coordinates).
var lineStringGeometry = new ymaps.geometry.LineString([
    [30, 50], [31, 51], [32, 52]
]),
// Instantiating the geo object and passing our geometry to the constructor.
    lineStringGeoObject = new ymaps.GeoObject({ geometry: lineStringGeometry });

lineStringGeometry.events.add('change', function (e) {
   alert([e.get('newCoordinates'), e.get('oldCoordinates')]);
});

// Changing vertexes via the geo object's "geometry" property (setting new coordinates for the second point on the line).
lineStringGeoObject.geometry
    .set(1, [20, 40])
    .remove(2);
// Or directly.
lineStringGeometry
    .set(1, [20, 40])
    .remove(2);
// You can also access lineStringGeometry via lineStringGeoObject.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.

Inherited from ILineStringGeometryAccess.

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
freeze()

IFreezable

Switches the object to "frozen" mode.

Inherited from IFreezable.

get(index)

Number[]

Returns coordinates of the point with the specified index.

Inherited from ILineStringGeometryAccess.

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)

IPointGeometryAccess

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

Inherited from ILineStringGeometryAccess.

getClosest(anchorPosition)

Object

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

Inherited from ILineStringGeometryAccess.

getCoordinates()

Number[][]

Returns an array of geometry coordinates.

Inherited from ILineStringGeometryAccess.

getDistance([from[, to]])

Number

Returns the length of the specified line segment, or the whole line, if the delimiter is not set.

getLength()

Integer

Returns the number of points in the geometry.

Inherited from ILineStringGeometryAccess.

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

Inherited from ILineStringGeometry.

insert(index, coordinates)

ILineStringGeometryAccess

Adds a new point with the specified index.

Inherited from ILineStringGeometryAccess.

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.

Inherited from ILineStringGeometryAccess.

set(index, coordinates)

ILineStringGeometryAccess

Sets coordinates of the point with the specified index.

Inherited from ILineStringGeometryAccess.

setCoordinates(coordinates)

ILineStringGeometryAccess

Sets an array of geometry coordinates.

Inherited from ILineStringGeometryAccess.

setMap(map)

Sets the map.

Inherited from IGeometry.

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.

Inherited from ILineStringGeometryAccess.

unfreeze()

IFreezable

Switches the object to active mode.

Inherited from IFreezable.

Methods details

getDistance

{Number} getDistance([from[, to]])

Returns the length of the specified line segment, or the whole line, if the delimiter is not set.

Parameters:

ParameterDefault valueDescription
from 0

Type: Number

Specifies the start point for calculating the length.

to

Type: Number

Specifies the end point for calculating the length. If not specified, the last point is used.

Example:

var lineStringGeometry = new ymaps.geometry.LineString([[30, 50], [31, 51], [32, 52]]),
    geoObject = new ymaps.GeoObject({ geometry: lineStringGeometry });
myMap.geoObjects.add(geoObject);
// The total length of the line.
console.log(geoObject.geometry.getDistance());
// The length of the segment from the first to the second point.
console.log(geoObject.geometry.getDistance(0, 1));