A
A
Alexander Naumov2018-08-24 18:19:42
Yandex maps
Alexander Naumov, 2018-08-24 18:19:42

How to change the marker by clicking on it in Yandex maps?

How to change the marker when clicking on it?
Here is the code.

ymaps.ready(function () {
    var myMap = new ymaps.Map('map', {
            center: [55.751574, 37.573856],
            zoom: 9
        }, {
            searchControlProvider: 'yandex#search'
        }),

        // Создаём макет содержимого.
        MyIconContentLayout = ymaps.templateLayoutFactory.createClass(
            '<div style="color: #FFFFFF; font-weight: bold;">$[properties.iconContent]</div>'
        ),

        myPlacemark = new ymaps.Placemark(myMap.getCenter(), {
            balloonContent: 'Это красивая метка'
        }, {
            // Опции.
            // Необходимо указать данный тип макета.
            iconLayout: 'default#image',
            // Своё изображение иконки метки.
            iconImageHref: 'img/marker.png',
            // Размеры метки.
           iconImageSize: [30, 40],
    iconImageOffset: [-15, -40],
    iconImageClipRect: [
      [0, 70],
      [30, 110]
    ],
        }),

        myPlacemarkWithContent = new ymaps.Placemark([55.661574, 37.573856], {
            balloonContent: 'А эта — новогодняя',
            iconContent: '12'
        }, {
            // Опции.
            // Необходимо указать данный тип макета.
            iconLayout: 'default#imageWithContent',
            // Своё изображение иконки метки.
            iconImageHref: 'img/marker.png',
            // Размеры метки.
            iconImageSize: [30, 40],
    iconImageOffset: [-15, -40],
    iconImageClipRect: [
      [0, 70],
      [30, 110]
    ]     });

    myMap.geoObjects
        .add(myPlacemark)
        .add(myPlacemarkWithContent);
});

Answer the question

In order to leave comments, you need to log in

3 answer(s)
0
0xD34F, 2018-08-24
@coderart

Hang a click handler, inside do options.set. For example .

Z
zooks, 2015-02-18
@zooks

Moved the header with utf-8 encoding.

S
Sergey Melnikov, 2015-02-18
@mlnkv

All pages of my site are saved in windows-1251 encoding.

So translate the site to utf-8, what's the problem?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question