O
O
Ockonal2014-07-30 16:31:19
JavaScript
Ockonal, 2014-07-30 16:31:19

How to attach data to a polygon?

Hello, I am using the latest version of yandex maps api (2.*). I create a polygon on the map:

polygonObj = new ymaps.GeoObject({
   geometry: {
      type: "Polygon",
      coordinates: polygon
   }
});

And I add a click handler to this polygon:
polygonObj.events.add('click', function (el) {
    console.log(el.get('target'));
});

So, inside the handler, I somehow need to identify this polygon, bind some data to it. All polygons are created in a loop and have an array with additional information.
There were ideas up to storing the index in the array inside the balloon-property and, upon clicking, getting the desired element from the array. But surely there is a normal method.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
O
Ockonal, 2014-07-30
@Ockonal

Ok, I found the answer myself. You need to use the event processing context (example at the very bottom).

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question