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

# Редактирование маршрута

<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/ru/router_editor/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/64nktp?file=index.html">Open in CodeSandbox</a>

<div id="references">
    <a href="https://yandex.ru/dev/jsapi-v2-1/doc/ru/v2-1/ref/reference/ready">ready</a>,
    <a href="https://yandex.ru/dev/jsapi-v2-1/doc/ru/v2-1/ref/reference/Map">Map</a>
</div>
<p>
    Ссылка на редактор маршрута находится в поле <a href="https://yandex.ru/dev/jsapi-v2-1/doc/ru/v2-1/ref/reference/router.Route#editor">editor</a> экземпляра класса router.Route, который будет передан в качестве параметра объекту <a href="https://yandex.ru/dev/jsapi-v2-1/doc/ru/v2-1/ref/reference/util.Promise">util.Promise</a> после того, как выполнится построение маршрута.
</p>
<p>
    Включать (выключать) редактор можно только внутри функции-обработчика, которая выполнится, когда от сервера придет результат.
</p>

{% list tabs %}

-   index.html

    ```html
    <!DOCTYPE html>

    <html>
        <head>
            <title>Редактирование маршрута</title>
            <meta
                http-equiv="Content-Type"
                content="text/html; charset=utf-8"
            />
            <!--
            Укажите свой API-ключ. Тестовый ключ НЕ БУДЕТ работать на других сайтах.
            Получить ключ можно в Кабинете разработчика: https://developer.tech.yandex.ru/keys/
        -->
            
            
            
            
        </head>

        <body>
            <div id="map"></div>
            <button value="Включить редактор маршрута" id="editor" name="start">
                Включить редактор маршрута
            </button>
        </body>
    </html>
    ```

-   router_editor.js

    ```js
    ymaps.ready(init);

    function init() {
        var myMap = new ymaps.Map(
                "map",
                {
                    center: [57.131311, 34.576128],
                    zoom: 5,
                },
                {
                    searchControlProvider: "yandex#search",
                }
            ),
            // Признак начала редактирования маршрута.
            startEditing = false,
            button = $("#editor");

        // Построение маршрута от станции метро Смоленская до станции Третьяковская.
        // Маршрут должен проходить через метро "Арбатская".
        ymaps
            .route(
                [
                    "Москва, метро Смоленская",
                    {
                        // Метро Арбатская - транзитная точка (проезжать через эту точку,
                        // но не останавливаться в ней).
                        type: "viaPoint",
                        point: "Москва, метро Арбатская",
                    },
                    // Метро "Третьяковская".
                    [55.744568, 37.60118],
                ],
                {
                    // Автоматически позиционировать карту.
                    mapStateAutoApply: true,
                }
            )
            .then(
                function (route) {
                    myMap.geoObjects.add(route);
                    button.click(function () {
                        if ((startEditing = !startEditing)) {
                            // Включаем редактор.
                            route.editor.start({
                                addWayPoints: true,
                                removeWayPoints: true,
                            });
                            button.text("Отключить редактор маршрута");
                        } else {
                            // Выключаем редактор.
                            route.editor.stop();
                            button.text("Включить редактор маршрута");
                        }
                    });
                    route.editor.events.add(
                        ["waypointadd", "waypointremove", "start"],
                        function () {
                            if (route.getWayPoints().getLength() >= 10) {
                                // Если на карте больше 9 точек маршрута, отключаем добавление новых точек.
                                route.editor.start({
                                    addWayPoints: false,
                                    removeWayPoints: true,
                                });
                            } else {
                                // Включаем добавление новых точек.
                                route.editor.start({
                                    addWayPoints: true,
                                    removeWayPoints: true,
                                });
                            }
                        }
                    );
                },
                function (error) {
                    alert("Возникла ошибка: " + error.message);
                }
            );
    }
    ```

{% endlist %}
