A
A
Anton2015-12-16 18:21:13
JavaScript
Anton, 2015-12-16 18:21:13

Yandex traffic jams on your site, how to connect the control panel?

Hello, I put a Yandex map with traffic jams on the site, how to connect the control panel buttons, search, zoom in or out on the map by clicking on the plus sign or minus sign on the map and other buttons, how to add them to the code?

The code:

<script type="text/javascript">
ymaps.ready(init);

function init () {
var myMap = new ymaps.Map('map', {
center: [43.131,131.924],
zoom: 14,
controls: []
});
// Создадим элемент управления "Пробки".
var trafficControl = new ymaps.control.TrafficControl({ state: {
// Отображаются пробки "Сейчас".
providerKey: 'traffic#actual',
// Начинаем сразу показывать пробки на карте.
trafficShown: true
}});
// Добавим контрол на карту.
myMap.controls.add(trafficControl);
// Получим ссылку на провайдер пробок "Сейчас" и включим показ инфоточек.
trafficControl.getProvider('traffic#actual').state.set('infoLayerShown', true);    
}
</script>

Answer the question

In order to leave comments, you need to log in

2 answer(s)
F
forgotten, 2015-12-16
Websaytovsky @ws17

They say reading the documentation sometimes helps.
https://tech.yandex.ru/maps/doc/jsapi/2.1/dg/conce...

A
Anton, 2015-12-17
Websaytovsky @ws17

I tried to add events to traffic jams so that they turn on themselves, it does not work.
Adding a "Traffic" control to the map:
myMap.controls.add('trafficControl');
Adding a "Traffic" control to the map with automatic activation and display of the traffic situation:
var trafficControl =
new ymaps.control.TrafficControl();
myMap.controls.add(trafficControl);
trafficControl.showTraffic();

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question