---
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_custom_balloon_layout.md
  - https://yandex.com.tr/dev/jsapi-v2-1/doc/ru/v2-1/examples/cases/multiroute_custom_balloon_layout.md
---
> **Documentation Index:** Fetch the complete configuration index at https://yandex.com.tr/dev/jsapi-v2-1/doc/en/llms.txt

# Custom layout for the multiroute balloon

<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_custom_balloon_layout/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/5t2kj3?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/templateLayoutFactory">templateLayoutFactory</a>
</div>
<p>
    Object layouts can be created using the <a href="https://yandex.ru/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/templateLayoutFactory">templateLayoutFactory</a> factory and
    text templates.
</p>
<p>
    This example creates a custom multiroute balloon layout that displays information about the selected route:
    each type of transport shows the route, the length of the route, and the travel time.
	The balloon layout is set via the multirouter option.
</p>

{% list tabs %}

-   index.html

    ```html
    <!DOCTYPE html>

    <html>
        <head>
            <title>Examples. Custom layout for the multiroute balloon</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_custom_balloon_layout.js

    ```js
    function init() {
        var myMap = new ymaps.Map("map", {
                center: [55.752625, 37.5981],
                zoom: 14,
                controls: [],
            }),
            /**
             * Creating your own layout using the layout factory.
             * @see https://api.yandex.com/maps/doc/jsapi/2.1/ref/reference/templateLayoutFactory.xml
             */
            balloonLayout = ymaps.templateLayoutFactory.createClass(
                "<div class='my-balloon'>" +
                    "<u>Route {% if properties.type == 'driving' %}" +
                    "Driving<br/>" +
                    "{% else %}" +
                    "Public transit" +
                    "{% endif %}</u><br />" +
                    "Distance: " +
                    "<i>{{ properties.distance.text }}</i>,<br />" +
                    "Travel time: " +
                    "<i>{{ properties.duration.text }} (without traffic) </i>." +
                    "</div>"
            ),
            /**
             * Creating a multiroute.
             * @see https://api.yandex.com/maps/doc/jsapi/2.1/ref/reference/multiRouter.MultiRoute.xml
             */
            multiRoute = new ymaps.multiRouter.MultiRoute(
                {
                    referencePoints: [
                        "Arbatskaya metro station",
                        "Smolenskaya metro station",
                    ],
                    params: {
                        /**
                         * avoidTrafficJams: true,
                         * routingMode: 'masstransit'
                         */
                    },
                },
                {
                    /**
                     * Geo object layout.
                     * @see https://api.yandex.com/maps/doc/jsapi/2.1/ref/reference/GeoObject.xml#param-options
                     */
                    balloonLayout: balloonLayout,
                    // Disabling the panel mode for the balloon.
                    balloonPanelMaxMapArea: 0,
                }
            );

        myMap.geoObjects.add(multiRoute);
    }

    ymaps.ready(init);
    ```

{% endlist %}
