Answer the question
In order to leave comments, you need to log in
How to loop through a collection of markers?
There is a map. You can place markers on it with the left mouse button. These markers are stored in localStorage. Each time the map is loaded, markers are taken from localStorage and applied to the map.
JSFILLDE here.
I put a click handler on the marker. When clicked, it turns green. But I would like that before this operation, iterate over all existing markers and paint them blue. Here is a piece of problematic code where I can't iterate over and recolor all the markers:
collectionMarkers.events.add('click', function(e) {
var target = e.get('target');
var id = target.properties.get('id');
console.log(id, target);
selectedMarker = id;
console.log('selectedMarker', selectedMarker);
var markers = myMap.geoObjects.each((geoObject) => {
console.log(geoObject.properties);
console.log(geoObject.properties.get('name'));
console.log(geoObject.properties.get('id'));
geoObject.options.set({
preset: 'islands#blueIcon',
});
});
e.get('target').options.set('preset', 'islands#greenIcon');
});
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question