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

# Building a multiroute on public transport

<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/multiroute_masstransit/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/63rnc2?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/multiRouter.MultiRoute">multiRouter.MultiRoute</a>,
    <a href="https://yandex.ru/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/multiRouter.MultiRouteModel">multiRouter.MultiRouteModel</a>,
    <a href="https://yandex.ru/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/control.Button">control.Button</a>
</div>
<p>
    In order to build a route on public transport, pass the
routingMode: 'masstransit' field in the routing parameters.
    By default, this field takes the 'auto' value when creating a multiroute.
</p>
<p>
    For more information about the multirouter parameters and options, see the example <a href="https://yandex.ru/dev/jsapi-v2-1/doc/en/v2-1/examples/cases/multiroute_driving">Building a driving multiroute</a>.
</p>

{% list tabs %}

-   index.html

    ```html
    <!DOCTYPE html>

    <html>
        <head>
            <title>Examples. Route on public transport</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>
    ```

-   multiroute_masstransit.js

    ```js
    function init() {
        /**
         * Creating a multiroute.
         * @see https://api.yandex.com/maps/doc/jsapi/2.1/ref/reference/multiRouter.MultiRoute.xml
         */
        var multiRoute = new ymaps.multiRouter.MultiRoute(
            {
                referencePoints: [[55.749, 37.524], "Moscow, Uspensky Lane, 7"],
                params: {
                    routingMode: "masstransit",
                },
            },
            {
                // Automatically set the map boundaries so the entire route is visible.
                boundsAutoApply: true,
            }
        );

        // Creating a button.
        var changeLayoutButton = new ymaps.control.Button({
            data: { content: "Show time for walking segments" },
            options: { selectOnClick: true },
        });

        // Declaring handlers for the button.
        changeLayoutButton.events.add("select", function () {
            multiRoute.options.set(
                // routeMarkerIconContentlayout - To show the time for all segments.
                "routeWalkMarkerIconContentLayout",
                ymaps.templateLayoutFactory.createClass(
                    "{{ properties.duration.text }}"
                )
            );
        });

        changeLayoutButton.events.add("deselect", function () {
            multiRoute.options.unset("routeWalkMarkerIconContentLayout");
        });

        // Creating the map with the button added to it.
        var myMap = new ymaps.Map(
            "map",
            {
                center: [55.739625, 37.5412],
                zoom: 12,
                controls: [changeLayoutButton],
            },
            {
                buttonMaxWidth: 300,
            }
        );

        // Adding a multiroute to the map.
        myMap.geoObjects.add(multiRoute);
    }

    ymaps.ready(init);
    ```

{% endlist %}
