---
metadata:
  - name: generator
    content: Diplodoc Platform v5.39.1
alternate:
  - https://yandex.com/dev/jsapi-v2-1/doc/en/v2-1/examples/cases/multiroute_custom_balloon_layout.md
  - https://yandex.com/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/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/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/p2xtm2?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/multiRouter.MultiRoute">multiRouter.MultiRoute</a>,
    <a href="https://yandex.ru/dev/jsapi-v2-1/doc/ru/v2-1/ref/reference/templateLayoutFactory">templateLayoutFactory</a>
</div>
<p>
    Макеты объектов можно создавать с помощью фабрики <a href="https://yandex.ru/dev/jsapi-v2-1/doc/ru/v2-1/ref/reference/templateLayoutFactory">templateLayoutFactory</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/
        -->
            
            <link
                href="https://yandex.st/bootstrap/2.3.2/css/bootstrap.min.css"
                rel="stylesheet"
            />
            
            
            
        </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: [],
            }),
            /**
             * Создание собственного макета с помощью фабрики макетов.
             * @see https://api.yandex.ru/maps/doc/jsapi/2.1/ref/reference/templateLayoutFactory.xml
             */
            balloonLayout = ymaps.templateLayoutFactory.createClass(
                "<div class='my-balloon'>" +
                    '<a class="close" href="#">&times;</a>' +
                    "<b>Маршрут {% if properties.type == 'driving' %}" +
                    "на автомобиле<br/>" +
                    "{% else %}" +
                    "на общественном транспорте" +
                    "{% endif %}</b><br />" +
                    "Расстояние: " +
                    "<i>{{ properties.distance.text }}</i>,<br />" +
                    "Время в пути: " +
                    "<i>{{ properties.duration.text }} (без учета пробок) </i>" +
                    "</div>",
                {
                    build: function () {
                        this.constructor.superclass.build.call(this);
                        this._$element = $(
                            ".my-balloon",
                            this.getParentElement()
                        );
                        this._$element
                            .find(".close")
                            .on("click", $.proxy(this.onCloseClick, this));
                    },

                    onCloseClick: function (e) {
                        e.preventDefault();
                        this.events.fire("userclose");
                    },
                }
            ),
            /**
             * Создание мультимаршрута.
             * @see https://api.yandex.ru/maps/doc/jsapi/2.1/ref/reference/multiRouter.MultiRoute.xml
             */
            multiRoute = new ymaps.multiRouter.MultiRoute(
                {
                    referencePoints: ["метро Арбатская", "метро Смоленская"],
                    params: {
                        // avoidTrafficJams: true,
                        //routingMode: 'masstransit'
                    },
                },
                {
                    /**
                     * Макет геообъекта.
                     * @see https://api.yandex.ru/maps/doc/jsapi/2.1/ref/reference/GeoObject.xml#param-options
                     */
                    balloonLayout: balloonLayout,
                    // Отключаем режим панели для балуна.
                    balloonPanelMaxMapArea: 0,
                }
            );

        myMap.geoObjects.add(multiRoute);
    }

    ymaps.ready(init);
    ```

{% endlist %}
