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

# Custom layout for the zoom control

<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/zoom_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/98gd5l?file=index.html">Open in CodeSandbox</a>

<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/control.ZoomControl">control.ZoomControl</a>,
    <a href="https://yandex.ru/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/templateLayoutFactory">templateLayoutFactory</a>
</div>
<p>
    <a href="https://yandex.ru/dev/jsapi-v2-1/doc/en/v2-1/dg/concepts/layouts">Layouts</a> of objects 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 layout for the <a href="https://yandex.ru/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/control.ZoomControl">map zoom control</a>.
The layout of the control is based on its data, status, and options.
The layout is automatically rebuilt when changes are made to the values of fields, states, or options that are used in its text template.
</p>
<p>
    In response to a user action (a mouse click on the button), the layout can generate special events that are defined in its interface. The control listens to these events on the layout and tries to change its state, data, or options. After the control has implemented changes, the layout is rebuilt based on the updated data.
</p>
<p>
    The events that the zoom slider responds to are listed in the <a href="https://yandex.ru/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/IZoomControlLayout">IZoomControlLayout</a> interface.
</p>

{% list tabs %}

-   index.html

    ```html
    <!DOCTYPE html>

    <html>
        <head>
            <title>Examples. Custom layout for the zoom control.</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/
        -->
            
            <link
                href="https://yandex.st/bootstrap/2.2.2/css/bootstrap.min.css"
                rel="stylesheet"
            />
            
            
            
        </head>
        <body>
            <div id="map"></div>
        </body>
    </html>
    ```

-   zoom_layout.js

    ```js
    ymaps.ready(init);

    function init() {
        var myMap = new ymaps.Map("map", {
                center: [55.751574, 37.573856],
                zoom: 9,
                controls: [],
            }),
            // Creating a custom layout for the zoom slider.
            ZoomLayout = ymaps.templateLayoutFactory.createClass(
                "<div>" +
                    "<div id='zoom-in' class='btn'><i class='icon-plus'></i></div><br>" +
                    "<div id='zoom-out' class='btn'><i class='icon-minus'></i></div>" +
                    "</div>",
                {
                    /**
                     * Redefining methods of the layout, in order to perform
                     * additional steps when building and clearing the layout.
                     */
                    build: function () {
                        // Calling the "build" parent method.
                        ZoomLayout.superclass.build.call(this);

                        /**
                         * Binding handler functions to the context and storing references
                         * to them in order to unsubscribe from the event later.
                         */
                        this.zoomInCallback = ymaps.util.bind(
                            this.zoomIn,
                            this
                        );
                        this.zoomOutCallback = ymaps.util.bind(
                            this.zoomOut,
                            this
                        );

                        // Beginning to listen for clicks on the layout buttons.
                        $("#zoom-in").bind("click", this.zoomInCallback);
                        $("#zoom-out").bind("click", this.zoomOutCallback);
                    },

                    clear: function () {
                        // Removing click handlers.
                        $("#zoom-in").unbind("click", this.zoomInCallback);
                        $("#zoom-out").unbind("click", this.zoomOutCallback);

                        // Calling the "clear" parent method.
                        ZoomLayout.superclass.clear.call(this);
                    },

                    zoomIn: function () {
                        var map = this.getData().control.getMap();
                        map.setZoom(map.getZoom() + 1, {
                            checkZoomRange: true,
                        });
                    },

                    zoomOut: function () {
                        var map = this.getData().control.getMap();
                        map.setZoom(map.getZoom() - 1, {
                            checkZoomRange: true,
                        });
                    },
                }
            ),
            zoomControl = new ymaps.control.ZoomControl({
                options: { layout: ZoomLayout },
            });

        myMap.controls.add(zoomControl);
    }
    ```

{% endlist %}
