---
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/en/llms.txt

# Editing a route

<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/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/7hp5fn?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>
</div>
<p>
    The link to the route editor is located in the <a href="https://yandex.ru/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/router.Route#editor">editor</a> field of the instance of the router.Route class that will be passed as a parameter to the <a href="https://yandex.ru/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/util.Promise">util.Promise</a> object after the route is built.
</p>
<p>
    The editor can only be turned on (off) inside the function that will be executed when the result comes from the server.
</p>

{% list tabs %}

-   index.html

    ```html
    <!DOCTYPE html>

    <html>
        <head>
            <title>Examples. Editing a route</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>
            <button value="Enable the route editor" id="editor" name="start">
                Enable the route editor
            </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",
                }
            ),
            // Indicates the beginning of route editing.
            startEditing = false,
            button = $("#editor");

        /**
         * Building a route from Smolenskaya metro station to Tretyakov station.
         * The route should pass through Arbatskaya station.
         */
        ymaps
            .route(
                [
                    "Moscow, Smolenskaya metro station",
                    {
                        /**
                         * Metro Arbatskaya is a through point (passing through this point,
                         * but not stopping at it).
                         */

                        type: "viaPoint",
                        point: "Moscow, metro Arbatskaya",
                    },
                    // Metro Tretyakovskaya.
                    [55.744568, 37.60118],
                ],
                {
                    // Automatically positioning the map.
                    mapStateAutoApply: true,
                }
            )
            .then(
                function (route) {
                    myMap.geoObjects.add(route);
                    button.click(function () {
                        if ((startEditing = !startEditing)) {
                            // Turning on the editor.
                            route.editor.start({
                                addWayPoints: true,
                                removeWayPoints: true,
                            });
                            button.text("Disable the route editor");
                        } else {
                            // Turning off the editor.
                            route.editor.stop();
                            button.text("Enable the route editor");
                        }
                    });
                    route.editor.events.add(
                        ["waypointadd", "waypointremove", "start"],
                        function () {
                            if (route.getWayPoints().getLength() >= 10) {
                                // Disabling adding new points if the map has more than 9 waypoints.
                                route.editor.start({
                                    addWayPoints: false,
                                    removeWayPoints: true,
                                });
                            } else {
                                // Enabling adding new points.
                                route.editor.start({
                                    addWayPoints: true,
                                    removeWayPoints: true,
                                });
                            }
                        }
                    );
                },
                function (error) {
                    alert("An error occurred: " + error.message);
                }
            );
    }
    ```

{% endlist %}
