Polyline editor

Open in CodeSandbox

A visual editor is available for polylines. A link to the editor is in the editor field of the polyline object.

<!DOCTYPE html>
<html>
    <head>
        <title>Examples. Polyline editor</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/
    -->
        <script
            src="https://api-maps.yandex.ru/2.1/?lang=en_RU&amp;apikey=<your API-key>"
            type="text/javascript"
        ></script>
        <script src="polylineEditor.js" type="text/javascript"></script>
        <style>
            html,
            body,
            #map {
                width: 100%;
                height: 100%;
                padding: 0;
                margin: 0;
            }
        </style>
    </head>
    <body>
        <div id="map"></div>
    </body>
</html>
ymaps.ready(init);

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

    // Creating a polyline.
    var myPolyline = new ymaps.Polyline(
        [
            // Specifying the coordinates of the vertices.
            [55.8, 37.5],
            [55.8, 37.4],
            [55.7, 37.5],
            [55.7, 37.4],
        ],
        {},
        {
            /**
             * Setting geo object options.
             * Color with transparency.
             */
            strokeColor: "#00000088",
            // The line width.
            strokeWidth: 4,
            // The maximum number of vertices in the polyline.
            editorMaxPoints: 6,
            // Adding a new item to the context menu that allows deleting the polyline.
            editorMenuManager: function (items) {
                items.push({
                    title: "Delete line",
                    onClick: function () {
                        myMap.geoObjects.remove(myPolyline);
                    },
                });
                return items;
            },
        }
    );

    // Adding a line to the map.
    myMap.geoObjects.add(myPolyline);

    // Turning on the edit mode.
    myPolyline.editor.startEditing();
}