Map behavior

Open in CodeSandbox

Interaction between the map and the user is programmed using behaviors.

The map behaviors are controlled by the behaviors manager. You should not have to create instances of this class. A reference to the behaviors manager is in the behaviors field of the map object.

<!DOCTYPE html>
<html>
    <head>
        <title>Examples. Map behaviors</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/
    -->
        <script
            src="https://api-maps.yandex.ru/2.1/?lang=en_RU&amp;apikey=<your API-key>"
            type="text/javascript"
        ></script>
        <script src="behaviors.js" type="text/javascript"></script>
        <style>
            html,
            body,
            #map {
                width: 100%;
                height: 100%;
                padding: 0;
                margin: 0;
            }
        </style>
    </head>
    <body>
        <div id="map"></div>
    </body>
</html>
var myMap;

ymaps.ready(init);

function init() {
    myMap = new ymaps.Map(
        "map",
        {
            // St. Petersburg
            center: [59.93772, 30.313622],
            zoom: 10,
        },
        {
            searchControlProvider: "yandex#search",
        }
    );

    myMap.behaviors
        /**
         * Disabling some of the behaviors enabled by default:
         * - drag - moving the map while holding down the left mouse button;
         * - magnifier.rightButton - zooming in on the area selected with the right mouse button.
         */
        .disable(["drag", "rightMouseButtonMagnifier"])
        // Enabling the ruler.
        .enable("ruler");

    /**
     * Using options to change the property of a behavior:
     * zooming with the scroll wheel will be slow,
     * 1/2 zoom level per second.
     */
    myMap.options.set("scrollZoomSpeed", 0.5);
}