I have an ObjectManager in which I add objects.

function createStation(coordinates, nameOfMyPolygon, background, id) { objectManager.add({ type: 'Feature', id: id, geometry: { type: 'Polygon', coordinates: coordinates }, properties: { name: nameOfMyPolygon }, options: { fillColor: background, labelDefaults: 'light', labelLayout: '{{properties.name}}' } }); } 

and I use this function 100 times and create and add 100 objects. Here is the code I use to hang on all objects in the object manager click event

 objectManager.events.add('click', () => { popupSectionInfo.classList.add('active'); priceSectionPopup.classList.remove('top'); popupSectionInfo.classList.add('top'); }); 

And now the fact that I can not understand. How can I hang on two different objects, two different click events? I would be glad if you can give an example.

Ps I read the documentation and I found the filters, but I figured out only how to display this or that object, but I did not understand how to attach the event to different objects ... Here is the link https://tech.yandex.ru/maps/doc/jsapi/ 2.1 / ref / reference / ObjectManager-docpage

  • In general, it is in one handler to determine the condition by which this or that object will be processed. - Dmytryk
  • You can determine which object was clicked through e.target and through if depending on the object to perform the desired action. - Reni
  • When I print e.target it gives undefined. - olishevskyalex
  • Here is the code objectManager.events.add ('click', (e) => {console.log (e.target); popupSectionInfo.classList.add ('active'); priceSectionPopup.classList.remove ('top'); popupSectionInfo .classList.add ('top');}); - olishevskyalex
  • I need the whole code example - Reni

1 answer 1

In general, I could not do two different events, but with the help of e.get ('objectId'), you can find the object id and use it to process what you need.