P
P
Pavel Grudinkin2016-09-05 21:49:30
JavaScript
Pavel Grudinkin, 2016-09-05 21:49:30

How to access a label by id?

I create labels like this

addressPointsCollection = new ymaps.GeoObjectCollection()
    addedAddressesCount = 0

    for address in addresses
      geoObject = new ymaps.GeoObject
        geometry:
          type: 'Point'
          coordinates: [address.latitude, address.longitude]
        properties:
          # iconContent: address.service.name
          hintContent: address.location
          id: address.id
      , preset: 'islands#darkGreenCircleDotIcon'


      addressPointsCollection.add geoObject
      addedAddressesCount += 1

      searchMap.geoObjects.add addressPointsCollection
      searchMap.setBounds(addressPointsCollection.getBounds(), { checkZoomRange: true });

Is it possible now knowing id ( id: address.id) to refer to the label, for example, to change the icon?
In general, I want the following: the user clicks-points the cursor on a list element that has a parameter with an id, a label is searched for this id and something changes in it, for example, the color of the icon.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Ruslan, 2016-09-06
@Hunt666

You won't be able to access the label through properties.id. You can create a global object (array) and add labels to it.
Add a label:
Then, at the right time, access the label, for example, to change the color:

objects[id].options.set('preset', 'islands#greenCircleDotIcon');

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question