Answer the question
In order to leave comments, you need to log in
How to add an event to ymaps.control.ListBoxItem when a menu item is selected?
new ymaps.control.ListBoxItem({
data: {
content: 'Владивосток',
center: [43.115536, 131.885485],
zoom: 9
}
})
new ymaps.control.ListBoxItem({
data: {
content: 'Екатеринбург',
center: [56.829103, 60.598939],
zoom: 16
},
events: {
click: function() {
alert(1);
}
}
}),
myPlacemark.events.add('click', function () {
alert('О, событие!');
});
Answer the question
In order to leave comments, you need to log in
const cityList = new ymaps.control.ListBox({
data: {
content: 'Select a city'
},
items: [
new ymaps.control.ListBoxItem('Moscow'),
new ymaps.control.ListBoxItem('Novosibirsk'),
new ymaps.control.ListBoxItem({
options: {
type: 'separator'
}
}),
new ymaps.control.ListBoxItem('New York'), ]
});
cityList.get(0)
.events.add('click', function () {
myMap.setCenter([55.752736, 37.606815]);
});
cityList.get(1)
.events.add('click', function () {
myMap.setCenter([55.026366, 82.907803]);
});
cityList.get(3)
.events.add('click', function () {
myMap.setCenter([40.695537, -73.97552]);
});
myMap.controls.add(cityList, {
floatIndex: 0
});
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question