Search code examples
yandex-maps

Set marker icon in Yandex Maps API


converting my Google maps code over to Yandex maps.

I have a function which updates the markers (placemarks) icon on the map.

In google maps i can do:

var newImage = new google.maps.MarkerImage('img/presence/' + marker.state.toLowerCase() + '_map.png');
marker.setIcon(newImage); 

I cannot find an equivilent method for setIcon in Yandex.

I can set the image at marker creation with:

var marker = new ymaps.Placemark(point, null, {
    iconImageHref: 'img/presence/'+state+'_map.png', 
    iconImageSize: [20, 20], 
    iconImageOffset: [-10, -20]
});

Any idea how i can update the icon image?


Solution

  • You can update options of existing placemark (marker):

    marker.options.set('iconImageHref', 'img/newImage.png');