N
N
Novomir Lobanov2015-10-12 11:38:51
JavaScript
Novomir Lobanov, 2015-10-12 11:38:51

How to change the icon on Yandex.maps by clicking on it?

There is a site with marks on the map,
I want to add the function of selecting a mark on the map by clicking on it.
I found such a function for changing parameters in the Yandex.map sandbox, but it does not work,
maybe you need to somehow redraw the labels?

myPlacemark549.properties
                .set({
                    iconImageHref: '/bitrix/templates/mosnt/img/Иконка_Активная.png'
                });

All label code
myPlacemark549 = new ymaps.Placemark([56.1440526,37.9992412],
    {

}, {
iconImageHref: '/bitrix/templates/mosnt/img/Иконка_Лукойл.png',
iconImageSize: [64, 64],
iconImageOffset: [-32, -64],
balloonContentSize: [270, 190]
});
    myPlacemark549.base = 549;
    myMap.geoObjects.add(myPlacemark549);
    myPlacemark549.events.add('click', function () {
        elem = $("#route-from").parents(".forselect").find("li[data-baza='#nb549']");
        $('.styledSelect').html($(elem).html()).removeClass('active');
        $('.custom-select').val($(elem).attr('rel'));
        $('.toplivo-table').css('display','none');
        $($(elem).data('baza')).css('display','block');
        $('#baza').html($(elem).html());

        myPlacemark549.properties
                .set({
                    iconImageHref: '/bitrix/templates/mosnt/img/Иконка_Активная.png'
                });

    });
    placemarks_list.push(myPlacemark549);

Answer the question

In order to leave comments, you need to log in

3 answer(s)
T
tennalian, 2015-10-12
@novomir

jsfiddle.net/tennalian/6pyr44yw

A
Alexander Zachinalov, 2015-10-12
@SanDiesel

try accessing the element via this rather than the name of the object within itself

F
forgotten, 2015-10-12
@forgotten

If version 2.1 is used, then you must additionally specify the iconLayout option: 'default#image'
https://tech.yandex.ru/maps/jsbox/2.1/

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question