E
E
Egor Ogurtsov2016-10-15 13:18:05
JavaScript
Egor Ogurtsov, 2016-10-15 13:18:05

How to get marker id?

There are several markers on the map, each marker has an ID property.
Everything is displayed like this

var shops = [
  {
    id: 12345,
    city: 42, 
    coordinates: [55.74,37.61],
    name: 'Название объекта', 
    desc: 'Адрес объекта в текстовом виде'
  },
  {
    id: 54321,
    city: 42, 
    coordinates: [55.47,37.16],
    name: 'Название объекта', 
    desc: 'Адрес объекта в текстовом виде'
  }
]

$.each(shops, function (index, value) {
    if (value.city == city) {
        points.push(new ymaps.Placemark(value.coordinates, {
            balloonHeader: value.name, 
            balloonContent: "<div class='my_ballon'><h2>" + value.name + "</h2><p>" + value.desc + '</p></div>'
        }, {  
            preset: "twirl#blueStretchyIcon",
            balloonShadow: false, 
            balloonPanelMaxMapArea: 0,
        //    iconColor: '#',
        })); 
       //Тут добавим айдишник и дату с айдишником неким элементам, при взаимодействии с которыми должно быть взаимодействие с  нужным маркером
        $('#art_' + value.id).attr('data-num', value.id);
    }
});

$.each(points, function (index, value) {
    myMap.geoObjects.add(value);
});

How to manipulate a certain marker knowing its ID, for example, change the color of the marker?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Rsa97, 2016-10-15
@mrdubz

Store not in an array, but in an object, that is

var points = {};
...
points[value.id] = new ymaps.Placemark(...);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question