Answer the question
In order to leave comments, you need to log in
How to show information when clicking on a Yandex map label?
Good afternoon, help me solve the issue with displaying information when clicking on the label
Here is the code
function init() {
// Создаем карту
myMap = new ymaps.Map("map", {
center: [53.9,27.5667],
zoom: 9,
controls: [
'zoomControl'
],
zoomMargin: [20]
});
for (var i = 0; i < shopList.length; i++) {
// Добавляем название города в выпадающий список
$('select#cities').append('<option value="' + i + '">' + shopList[i].cityName + '</option>');
// Создаём коллекцию меток для города
var cityCollection = new ymaps.GeoObjectCollection();
for (var c = 0; c < shopList[i].shops.length; c++) {
var shopInfo = shopList[i].shops[c];
var shopPlacemark = new ymaps.Placemark(
shopInfo.coordinates,
{
hintContent: shopInfo.name,
balloonContent: shopInfo.name,
WarehouseId: shopInfo.WarehouseId
},
{
preset: 'islands#redDotIcon'
}
);
if (!placemarkList[i]) placemarkList[i] = {};
placemarkList[i][c] = shopPlacemark;
// Добавляем метку в коллекцию
cityCollection.add(shopPlacemark);
}
placemarkCollections[i] = cityCollection;
// Добавляем коллекцию на карту
myMap.geoObjects.add(cityCollection);
}
$('select#cities').trigger('change');
myMap.geoObjects.events.add('click', function (e) {
console.log(shopPlacemark.properties.get('balloonContent'));
});
}
myMap.geoObjects.events.add('click', function (e) {
console.log(shopPlacemark.properties.get('balloonContent'));
});
Answer the question
In order to leave comments, you need to log in
Having looked better at the documentation, came to a solution, first, through the target, we get a link to the object with parameters, then we pull out the parameter that we need
var target = e.get('target');
console.log(target.properties.get('WarehouseId'));
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question