Skip to content

Instantly share code, notes, and snippets.

@khripunovpp
Last active March 11, 2017 19:17
Show Gist options
  • Save khripunovpp/e380008d0b4dc123527d458069f1d47e to your computer and use it in GitHub Desktop.
Save khripunovpp/e380008d0b4dc123527d458069f1d47e to your computer and use it in GitHub Desktop.
yandex-map-with-list-bootstrap-adaptive
***********************
groups.js
***********************
// Группы объектов
var items = [
{
name: "Монумент "Родина-Мать"",
style: "islands#redIcon",
center: [50.426472, 30.563022]
},
{
name: "Ресторан "Калинка-Малинка"",
style: "islands#greenIcon",
center: [50.50955, 30.60791]
},
{
name: "Музей грамзаписи и старинных музыкальных инструментов",
style: "islands#orangeIcon",
center: [50.443334, 30.520163]
},
{
name: "Замок Ричарда-Львиное сердце",
style: "islands#blueIcon",
center: [50.45987, 30.516174]
}
];
*********************
object_list.js
*********************
ymaps.ready(init);
function init() {
var myMap = new ymaps.Map('map', {
center: items[0].center,
zoom: 14
}, {
searchControlProvider: 'yandex#search'
}),
menu = $('<ul class="menu list-group"></ul>');
for (var i = 0, l = items.length; i < l; i++) {
createMenu(items[i]);
}
function createMenu (item) {
var menuItem = $('<li class="menu-item list-group-item"><a href="#">' + item.name + '</a></li>'),
placemark = new ymaps.Placemark(item.center, { balloonContent: item.name }, {preset: item.style});
myMap.geoObjects.add(placemark);
menuItem
.appendTo(menu)
.find('a')
.bind('click', function () {
if (!placemark.balloon.isOpen()) {
placemark.balloon.open();
} else {
placemark.balloon.close();
}
myMap.panTo(item.center, {flying: 1});
return false;
});
}
menu.appendTo($('#menu'));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment