---
metadata:
  - name: generator
    content: Diplodoc Platform v5.39.1
alternate:
  - https://yandex.com.tr/dev/jsapi-v2-1/doc/ru/v2-1/examples/cases/placemark_layout.md
---
> **Documentation Index:** Fetch the complete configuration index at https://yandex.com.tr/dev/jsapi-v2-1/doc/ru/llms.txt

# Анимация метки

<iframe id="LIVE-EXAMPLE" style="width:100%;height: 400px;border-radius: 8px;border: 1px solid rgba(92, 94, 102, 0.14);" frameBorder="0" src="https://yastatic.net/s3/front-maps-static/maps-front-jsapi-v2-1/examples/2/out/s3-cases/ru/placemark_layout/index.html" allow="fullscreen"></iframe>

<a target="_blank" rel="noopener noreferrer" style="display: inline-block;margin-top: 10px;cursor: pointer;border-radius: 4px;padding: 9px 12px;background: #151515;color: white;text-decoration: none;font-weight: 500" href="https://codesandbox.io/p/sandbox/krycsh?file=index.html">Open in CodeSandbox</a>

<div id="references">
    <a href="https://yandex.ru/dev/jsapi-v2-1/doc/ru/v2-1/ref/reference/Placemark">Placemark</a>,
    <a href="https://yandex.ru/dev/jsapi-v2-1/doc/ru/v2-1/ref/reference/templateLayoutFactory">templateLayoutFactory</a>
</div>
<p>
    В данном примере показано, как создать анимированную метку. При нажатии на метку, она превратится в каплю.
</p>
<p>
    Для того, чтобы изменить внешний вид метки, нужно задать ей собственный макет. Создание своего макета метки происходит при помощи <a href="https://yandex.ru/dev/jsapi-v2-1/doc/ru/v2-1/ref/reference/templateLayoutFactory-docpage/">фабрики макетов</a>.
</p>

{% list tabs %}

-   index.html

    ```html
    <!DOCTYPE html>
    <html>
        <head>
            <meta
                http-equiv="Content-Type"
                content="text/html; charset=utf-8"
            />
            <title>Анимация метки</title>
            <!--
            Укажите свой API-ключ. Тестовый ключ НЕ БУДЕТ работать на других сайтах.
            Получить ключ можно в Кабинете разработчика: https://developer.tech.yandex.ru/keys/
        -->
            
            
            
        </head>
        <body>
            <p>Кликните по метке, чтобы увидеть анимацию</p>
            <div id="map"></div>
        </body>
    </html>
    ```

-   placemark_layout.js

    ```js
    ymaps.ready(function () {
        var map = new ymaps.Map("map", {
            center: [55.755, 37.617],
            zoom: 10,
        });
        // Создадим макет метки.
        var animatedLayout = ymaps.templateLayoutFactory.createClass(
            '<div class="placemark"></div>',
            {
                build: function () {
                    animatedLayout.superclass.build.call(this);
                    var element =
                        this.getParentElement().getElementsByClassName(
                            "placemark"
                        )[0];
                    // Если метка выбрана, то увеличим её размер.
                    var size = this.isActive ? 60 : 34;
                    // При задании для метки своего HTML макета, фигуру активной области
                    // необходимо задать самостоятельно - иначе метка будет неинтерактивной.
                    // Создадим фигуру активной области "Круг".
                    var smallShape = {
                        type: "Circle",
                        coordinates: [0, 0],
                        radius: size / 2,
                    };
                    var bigShape = {
                        type: "Circle",
                        coordinates: [0, -30],
                        radius: size / 2,
                    };
                    // Зададим фигуру активной области.
                    this.getData().options.set(
                        "shape",
                        this.isActive ? bigShape : smallShape
                    );
                    // Если метка выбрана, то зададим класс и запустим анимацию.
                    if (this.isActive) {
                        element.classList.add("active");
                        element.style.animation = ".35s show-big-placemark";
                    } else if (this.inited) {
                        element.classList.remove("active");
                        element.style.animation = ".35s show-small-placemark";
                    }
                    if (!this.inited) {
                        this.inited = true;
                        this.isActive = false;
                        // При клике по метке будем перестраивать макет.
                        this.getData().geoObject.events.add(
                            "click",
                            function () {
                                this.isActive = !this.isActive;
                                this.rebuild();
                            },
                            this
                        );
                    }
                },
            }
        );
        map.geoObjects.add(
            new ymaps.Placemark(
                [55.755, 37.617],
                {},
                {
                    iconLayout: animatedLayout,
                    hasBalloon: false,
                }
            )
        );
    });
    ```

{% endlist %}
