Answer the question
In order to leave comments, you need to log in
How to change the balloon text of a label added via the ObjectManager (Yandex Maps API)?
I have a map with many dots on it. The points are added using the ObjectManager :
const map = new ymaps.Map(document.getElementById('map'), {
center: [42, 54],
zoom: 6
});
const objectManager = new ymaps.ObjectManager({
clusterize: true
});
objectManager.add({
type: 'FeatureCollection',
features: [
{
type: 'Feature',
id: 1,
geometry: {
type: 'Point',
coordinates: [43, 54]
},
properties: {
balloonContentBody: 'Загрузка...'
}
},
{
type: 'Feature',
id: 2,
geometry: {
type: 'Point',
coordinates: [41, 55]
},
properties: {
balloonContentBody: 'Загрузка...'
}
}
// ...
]
});
map.geoObjects.add(objectManager);
objectManager.objects.setObjectOptions(1, {
preset: 'islands#redIcon',
balloonContentBody: 'Загружено (тут полезная информация)',
properties: {
balloonContentBody: 'Загружено (тут полезная информация)'
}
});
Answer the question
In order to leave comments, you need to log in
objectManager.objects.getById(1).properties.balloonContentBody = 'Загружено (тут полезная информация)';
objectManager.objects.getById
may return null
. Demo on CodePen . https://tech.yandex.ru/maps/doc/jsapi/2.1/ref/refe...
There is an example in the description of the add method.
I'll quote this example:
var myObjectManager = new ymaps.ObjectManager({ clusterize: true }),
currentId = 0;
// Добавление единичного объекта.
myObjectManager.add({
type: 'Feature',
id: currentId++,
geometry: {
type: 'Point',
coordinates: [56.23, 34.79]
},
properties: {
hintContent: 'Текст всплывающей подсказки',
balloonContent: 'Содержимое балуна'
}
});
map.geoObjects.add(objectManager);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question