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

# The layout of the placemark hint

<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/en/placemark_hint_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/42ypzh?file=index.html">Open in CodeSandbox</a>

<div id="doc">
    <div id="references">
        <a href="https://yandex.ru/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/ready">ready</a>, <a href="https://yandex.ru/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/Map">Map</a>,
        <a href="https://yandex.ru/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/Placemark">Placemark</a>, <a href="https://yandex.ru/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/templateLayoutFactory">templateLayoutFactory</a>
    </div>
    <p>
        Object layouts can be created using the <a href="https://yandex.ru/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/templateLayoutFactory">templateLayoutFactory</a> factory
        and text templates.
    </p>
    <p>
        This example creates a custom hint layout for the <a href="https://yandex.ru/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/GeoObject">geo object</a>.
        The layout is set for the geo object via the options.
    </p>
    <p>In order for the hint to automatically shift its position if it goes outside of the map container,
    redefine the <a href="https://yandex.ru/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/IOverlay#getShape">getShape()</a> method in its layout. This method should return the current size of the hint layout.</p>
</div>

{% list tabs %}

-   index.html

    ```html
    <!DOCTYPE html>

    <html>
        <head>
            <title>Examples. Custom hint layout</title>
            <meta
                http-equiv="Content-Type"
                content="text/html; charset=UTF-8"
            />
            <!--
            Set your own API-key. Testing key is not valid for other web-sites and services.
            Get your API-key on the Developer Dashboard: https://developer.tech.yandex.ru/keys/
        -->
            
            
            
        </head>

        <body>
            <div id="map"></div>
        </body>
    </html>
    ```

-   placemark_hint_layout.js

    ```js
    ymaps.ready(init);

    function init() {
        var myMap = new ymaps.Map(
                "map",
                {
                    center: [55.76, 37.64],
                    zoom: 10,
                },
                {
                    searchControlProvider: "yandex#search",
                }
            ),
            /**
             * Creating a layout for hint content.
             * The layout is created through the layout factory using a text template.
             */
            HintLayout = ymaps.templateLayoutFactory.createClass(
                "<div class='my-hint'>" +
                    "<b>{{ properties.object }}</b><br />" +
                    "{{ properties.address }}" +
                    "</div>",
                {
                    /**
                     * Defining the getShape method,
                     * which will return the size of the hint layout.
                     * This is necessary in order for the hint to automatically
                     * move its position when going off the map.
                     */
                    getShape: function () {
                        var el = this.getElement(),
                            result = null;
                        if (el) {
                            var firstChild = el.firstChild;
                            result = new ymaps.shape.Rectangle(
                                new ymaps.geometry.pixel.Rectangle([
                                    [0, 0],
                                    [
                                        firstChild.offsetWidth,
                                        firstChild.offsetHeight,
                                    ],
                                ])
                            );
                        }
                        return result;
                    },
                }
            );

        var myPlacemark = new ymaps.Placemark(
            [55.764286, 37.581408],
            {
                address: "Moscow, Zoologicheskaya Street, 13u2",
                object: "Contemporary Art Center",
            },
            {
                hintLayout: HintLayout,
            }
        );

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

{% endlist %}
