---
metadata:
  - name: generator
    content: Diplodoc Platform v5.39.1
alternate:
  - https://yandex.com.tr/dev/jsapi-v2-1/doc/en/v2-1/examples/cases/polyline.md
  - https://yandex.com.tr/dev/jsapi-v2-1/doc/ru/v2-1/examples/cases/polyline.md
---
> **Documentation Index:** Fetch the complete configuration index at https://yandex.com.tr/dev/jsapi-v2-1/doc/en/llms.txt

# Polyline

<iframe id="LIVE-EXAMPLE" style="width:100%;height: 400px;border-radius: 8px;border: 1px solid rgba(92, 94, 102, 0.14);" frameBorder="0" src="https://yastatic.net/s3/front-maps-static/maps-front-jsapi-v2-1/examples/2/out/s3-cases/en/polyline/index.html" allow="fullscreen"></iframe>

<a target="_blank" rel="noopener noreferrer" style="display: inline-block;margin-top: 10px;cursor: pointer;border-radius: 4px;padding: 9px 12px;background: #151515;color: white;text-decoration: none;font-weight: 500" href="https://codesandbox.io/p/sandbox/8rqv6h?file=index.html">Open in CodeSandbox</a>

<div id="references">
    <a href="https://yandex.ru/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/ready">ready</a>,
    <a href="https://yandex.ru/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/Map">Map</a>,
    <a href="https://yandex.ru/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/GeoObject">GeoObject</a>,
    <a href="https://yandex.ru/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/Polyline">Polyline</a>,
    <a href="https://yandex.ru/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/map.GeoObjects">map.GeoObjects</a>
</div>
<p>
    A polyline is a shape consisting of a set of sequentially connected vertices. The polyline can have self-intersections.
</p>
<p>
    The polyline can be created in two ways: using the <a href="https://yandex.ru/dev/jsapi-v2-1/doc/en/v2-1/dg/concepts/geoobjects">GeoObject</a>
    class with the "Polyline" geometry type,
    or using the <a href="https://yandex.ru/dev/jsapi-v2-1/doc/en/v2-1/dg/concepts/geoobjects#geometry">Polyline</a> auxiliary class.
</p>
<p>
    When creating a polyline, you can set <a href="https://yandex.ru/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/GeoObject#constructor-summary">properties</a>
    (such as the contents of a balloon or hint) and
    <a href="https://yandex.ru/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/GeoObject#constructor-summary">options</a> (such as color and line width).
</p>
<p>
    Polylines, like other geo objects, can be combined in <a href="https://yandex.ru/dev/jsapi-v2-1/doc/en/v2-1/dg/concepts/geoobjects#geoobject_collections">collections</a>.
</p>

{% list tabs %}

-   index.html

    ```html
    <!DOCTYPE html>
    <html>
        <head>
            <title>Examples. Polylines</title>
            <meta
                http-equiv="Content-Type"
                content="text/html; charset=UTF-8"
            />
            <!--
            Set your own API-key. Testing key is not valid for other web-sites and services.
            Get your API-key on the Developer Dashboard: https://developer.tech.yandex.ru/keys/
        -->
            
            
            
        </head>
        <body>
            <div id="map"></div>
        </body>
    </html>
    ```

-   polyline.js

    ```js
    ymaps.ready(init);

    function init() {
        // Creating the map.
        var myMap = new ymaps.Map(
            "map",
            {
                center: [55.72, 37.44],
                zoom: 10,
            },
            {
                searchControlProvider: "yandex#search",
            }
        );

        // Creating a polyline using the GeoObject class.
        var myGeoObject = new ymaps.GeoObject(
            {
                // Describing the geometry of the geo object.
                geometry: {
                    // The "Polyline" geometry type.
                    type: "LineString",
                    // Specifying the coordinates of the vertices of the polyline.
                    coordinates: [
                        [55.8, 37.5],
                        [55.7, 37.4],
                    ],
                },
                // Defining properties of the geo object.
                properties: {
                    // The contents of the hint.
                    hintContent: "I'm a geo object",
                    // The contents of the balloon.
                    balloonContent: "You can drag me",
                },
            },
            {
                /**
                 * Setting the geo object options.
                 *  Enabling drag-n-drop for the polyline.
                 */
                draggable: true,
                // The line color.
                strokeColor: "#FFFF00",
                // Line width.
                strokeWidth: 5,
            }
        );

        // Creating a polyline using the Polyline auxiliary class.
        var myPolyline = new ymaps.Polyline(
            [
                // Specifying the coordinates of the vertices of the polyline.
                [55.8, 37.5],
                [55.8, 37.4],
                [55.7, 37.5],
                [55.7, 37.4],
            ],
            {
                /**
                 * Describing the properties of the geo object.
                 *  The contents of the balloon.
                 */
                balloonContent: "Polyline",
            },
            {
                /**
                 * Setting options for the geo object. Disabling the close button on a balloon.
                 *
                 */
                balloonCloseButton: false,
                // The line color.
                strokeColor: "#000000",
                // Line width.
                strokeWidth: 4,
                // The transparency coefficient.
                strokeOpacity: 0.5,
            }
        );

        // Adding lines to the map.
        myMap.geoObjects.add(myGeoObject).add(myPolyline);
    }
    ```

{% endlist %}
