K
K
kmm design2014-09-16 16:32:11
JavaScript
kmm design, 2014-09-16 16:32:11

How to add a balloon to a regular route in Yandex Maps?

There is a Yandex.Maps API in the Sandbox ( api.yandex.ru/maps/jsbox/2.1/multiroute_custom_bal... an example of how to change the Multiroute balloon

var balloonLayout = ymaps.templateLayoutFactory.createClass(
            "<div class='my-balloon'>" +
                "<u>Маршрут {% if properties.type == 'driving' %}" +
                "на автомобиле<br/>" +
                "{% else %}" +
                "на общественном транспорте" +
                "{% endif %}</u><br />" +
                "Расстояние: " +
                "<i>{{ properties.distance.text }}</i>,<br />" +
                "Время в пути: " +
                "<i>{{ properties.duration.text }} (без учета пробок) </i>." +
                "</div>"
        ),
 multiRoute = new ymaps.multiRouter.MultiRoute({
            referencePoints: [
                "метро Арбатская",
                "метро Смоленская"
            ]
        }, {
            /**
             * Макет геообъекта.
             * @see http://api.yandex.ru/maps/doc/jsapi/2.1/ref/reference/GeoObject.xml#param-options
             */
            balloonLayout: balloonLayout,
            // Отключаем режим панели для балуна.
            balloonPanelMaxMapArea: 0
        });

    myMap.geoObjects.add(multiRoute);

, but this example doesn't fit the regular route .
There is an example of how to add a balloon to a regular route ( api.yandex.ru/maps/doc/jsapi/2.1/ref/reference/rou... Example 1
ymaps.route([
    'Королев',
    { type: 'viaPoint', point: 'Мытищи' },
    'Химки',
    { type: 'wayPoint', point: [55.811511, 37.312518] }
], {
    mapStateAutoApply: true
}).then(function (route) {
    route.getPaths().options.set({
        // в балуне выводим только информацию о времени движения с учетом пробок
        balloonContentBodyLayout: ymaps.templateLayoutFactory.createClass('<div>ok</div>'),
        // можно выставить настройки графики маршруту
        strokeColor: '0000ffff',
        opacity: 0.9
    });
    // добавляем маршрут на карту
    map.geoObjects.add(route);
});

But the balloonContentBodyLayout property does n't work. I tried both in the Yandex.Maps API Sandbox and in my own place - the content of the balloon does not change.
Help add a balloon to the regular route . Thank you!

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question