Restrict the map view area

<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8" />
        <meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1" />
        <script crossorigin src="https://cdn.jsdelivr.net/npm/@babel/standalone@7/babel.min.js"></script>
        <!-- To make the map appear, you must add your apikey -->
        <script src="https://api-maps.yandex.ru/v3/?apikey=<YOUR_APIKEY>&lang=en_US" type="text/javascript"></script>

        <script
            data-plugins="transform-modules-umd"
            data-presets="typescript"
            type="text/babel"
            src="../variables.ts"
        ></script>
        <script
            data-plugins="transform-modules-umd"
            data-presets="typescript"
            type="text/babel"
            src="./common.ts"
        ></script>
        <script data-plugins="transform-modules-umd" data-presets="typescript" type="text/babel">
            import {RESTRICTION_TOOLTIP_TEXT} from './common';
            import {POLYGON_COORDINATES, RESTRICT_AREA, ZOOM_RANGE} from '../variables';
            
            window.map = null;
            
            main();
            
            async function main() {
                // Waiting for all api elements to be loaded
                await ymaps3.ready;
                const {YMap, YMapDefaultSchemeLayer, YMapDefaultFeaturesLayer, YMapFeature, YMapControls, YMapComplexEntity} =
                    ymaps3;
                // Initialize the map
                map = new YMap(
                    // Pass the link to the HTMLElement of the container
                    document.getElementById('app'),
                    // Pass the map initialization parameters, set the map location bounds with the current restricted area
                    {
                        location: {bounds: RESTRICT_AREA},
                        restrictMapArea: RESTRICT_AREA,
                        zoomRange: ZOOM_RANGE
                    },
                    // Add a map schema layer and a geo objects layer
                    [new YMapDefaultSchemeLayer({}), new YMapDefaultFeaturesLayer({})]
                );
            
                // Create and add a polygon to the map that will mark the border of the map restrict area
                const borderPolygon = new YMapFeature({
                    id: 'polygon',
                    geometry: {
                        type: 'Polygon',
                        coordinates: [POLYGON_COORDINATES]
                    },
                    style: {
                        stroke: [{width: 12, color: '#122DB2'}],
                        fill: 'rgba(0, 0, 0, 0)'
                    }
                });
                map.addChild(borderPolygon);
            
                class RestrictionTooltip extends YMapComplexEntity<{}> {
                    private _element: HTMLDivElement;
            
                    private _detachDom: () => void;
            
                    // Method for create a DOM control element
                    _createElement() {
                        const tooltipElement = document.createElement('div');
            
                        tooltipElement.innerHTML = RESTRICTION_TOOLTIP_TEXT;
                        tooltipElement.classList.add('restriction_tooltip');
                        return tooltipElement;
                    }
            
                    // Method for attaching the control to the map
                    _onAttach() {
                        this._element = this._createElement();
                        this._detachDom = ymaps3.useDomContext(this, this._element, this._element);
                    }
            
                    // Method for detaching control from the map
                    _onDetach() {
                        this._detachDom();
                        this._detachDom = null;
                        this._element = null;
                    }
                }
            
                const tooltip = new RestrictionTooltip({});
            
                // Add a container for YMapControlButton and add it to the map
                const controls = new YMapControls({position: 'top left'});
                controls.addChild(tooltip);
                map.addChild(controls);
            }
        </script>

        <style> html, body, #app { width: 100%; height: 100%; margin: 0; padding: 0; font-family: Arial, Helvetica, sans-serif; } .toolbar { position: absolute; z-index: 1000; top: 0; left: 0; display: flex; align-items: center; padding: 16px; } .toolbar a { padding: 16px; }  </style>
        <link rel="stylesheet" href="./common.css" />
        <link rel="stylesheet" href="../variables.css" />
    </head>
    <body>
        <div id="app"></div>
    </body>
</html>
<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8" />
        <meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1" />
        <script crossorigin src="https://cdn.jsdelivr.net/npm/react@17/umd/react.production.min.js"></script>
        <script crossorigin src="https://cdn.jsdelivr.net/npm/react-dom@17/umd/react-dom.production.min.js"></script>
        <script crossorigin src="https://cdn.jsdelivr.net/npm/@babel/standalone@7/babel.min.js"></script>
        <!-- To make the map appear, you must add your apikey -->
        <script src="https://api-maps.yandex.ru/v3/?apikey=<YOUR_APIKEY>&lang=en_US" type="text/javascript"></script>

        <script
            data-plugins="transform-modules-umd"
            data-presets="typescript"
            type="text/babel"
            src="../variables.ts"
        ></script>
        <script
            data-plugins="transform-modules-umd"
            data-presets="typescript"
            type="text/babel"
            src="./common.ts"
        ></script>
        <script data-plugins="transform-modules-umd" data-presets="react, typescript" type="text/babel">
            import {RESTRICTION_TOOLTIP_TEXT} from './common';
            import {POLYGON_COORDINATES, RESTRICT_AREA, ZOOM_RANGE} from '../variables';
            
            window.map = null;
            
            main();
            
            async function main() {
                // For each object in the JS API, there is a React counterpart
                // To use the React version of the API, include the module @yandex/ymaps3-reactify
                const [ymaps3React] = await Promise.all([ymaps3.import('@yandex/ymaps3-reactify'), ymaps3.ready]);
                const reactify = ymaps3React.reactify.bindTo(React, ReactDOM);
                const {YMap, YMapDefaultSchemeLayer, YMapDefaultFeaturesLayer, YMapFeature, YMapControls, YMapControl} =
                    reactify.module(ymaps3);
            
                function App() {
                    return (
                        // Initialize the map and pass initialization parameters, set the map location bounds with the current restricted area
                        <YMap
                            location={{bounds: RESTRICT_AREA}}
                            restrictMapArea={RESTRICT_AREA}
                            zoomRange={ZOOM_RANGE}
                            ref={(x) => (map = x)}
                        >
                            {/* Add a map schema layer and a geo objects layer */}
                            <YMapDefaultSchemeLayer />
                            <YMapDefaultFeaturesLayer />
            
                            {/* Add a polygon to the map that will mark the border of the map restrict area */}
                            <YMapFeature
                                geometry={{
                                    type: 'Polygon',
                                    coordinates: [POLYGON_COORDINATES]
                                }}
                                style={{
                                    stroke: [{width: 12, color: '#122DB2'}],
                                    fill: 'rgba(0, 0, 0, 0)'
                                }}
                            />
            
                            {/* Add YMapControlButton that changes the restricted area */}
                            <YMapControls position="top left">
                                <YMapControl transparent>
                                    <div
                                        className="restriction_tooltip"
                                        dangerouslySetInnerHTML={{__html: RESTRICTION_TOOLTIP_TEXT}}
                                    ></div>
                                </YMapControl>
                            </YMapControls>
                        </YMap>
                    );
                }
            
                ReactDOM.render(
                    <React.StrictMode>
                        <App />
                    </React.StrictMode>,
                    document.getElementById('app')
                );
            }
        </script>

        <style> html, body, #app { width: 100%; height: 100%; margin: 0; padding: 0; font-family: Arial, Helvetica, sans-serif; } .toolbar { position: absolute; z-index: 1000; top: 0; left: 0; display: flex; align-items: center; padding: 16px; } .toolbar a { padding: 16px; }  </style>
        <link rel="stylesheet" href="./common.css" />
        <link rel="stylesheet" href="../variables.css" />
    </head>
    <body>
        <div id="app"></div>
    </body>
</html>
<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8" />
        <meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1" />
        <script crossorigin src="https://cdn.jsdelivr.net/npm/vue@3/dist/vue.global.js"></script>
        <script crossorigin src="https://cdn.jsdelivr.net/npm/@babel/standalone@7/babel.min.js"></script>
        <!-- To make the map appear, you must add your apikey -->
        <script src="https://api-maps.yandex.ru/v3/?apikey=<YOUR_APIKEY>&lang=en_US" type="text/javascript"></script>

        <script
            data-plugins="transform-modules-umd"
            data-presets="typescript"
            type="text/babel"
            src="../variables.ts"
        ></script>
        <script
            data-plugins="transform-modules-umd"
            data-presets="typescript"
            type="text/babel"
            src="./common.ts"
        ></script>
        <script data-plugins="transform-modules-umd" data-presets="typescript" type="text/babel">
            import {RESTRICTION_TOOLTIP_TEXT} from './common';
            import {POLYGON_COORDINATES, RESTRICT_AREA, ZOOM_RANGE} from '../variables';
            
            window.map = null;
            
            async function main() {
                // For each object in the JS API, there is a Vue counterpart
                // To use the Vue version of the API, include the module @yandex/ymaps3-vuefy
                const [ymaps3Vue] = await Promise.all([ymaps3.import('@yandex/ymaps3-vuefy'), ymaps3.ready]);
                const vuefy = ymaps3Vue.vuefy.bindTo(Vue);
                const {YMap, YMapDefaultSchemeLayer, YMapDefaultFeaturesLayer, YMapFeature, YMapControls, YMapControl} =
                    vuefy.module(ymaps3);
            
                const App = Vue.createApp({
                    components: {
                        YMap,
                        YMapDefaultSchemeLayer,
                        YMapDefaultFeaturesLayer,
                        YMapFeature,
                        YMapControls,
                        YMapControl
                    },
                    setup() {
                        const refMap = (ref) => {
                            window.map = ref?.entity;
                        };
            
                        return {RESTRICTION_TOOLTIP_TEXT, refMap, RESTRICT_AREA, ZOOM_RANGE, POLYGON_COORDINATES};
                    },
                    template: `
                  <YMap
                    :location="{ bounds: RESTRICT_AREA }"
                    :restrictMapArea="RESTRICT_AREA"
                    :zoomRange="ZOOM_RANGE"
                    :ref="refMap"
                  >
                    <YMapDefaultSchemeLayer />
                    <YMapDefaultFeaturesLayer />
                    <YMapFeature
                      :geometry="{
                        type: 'Polygon',
                        coordinates: [POLYGON_COORDINATES]
                      }"
                      :style="{
                        stroke: [{ width: 12, color: '#122DB2' }],
                        fill: 'rgba(0, 0, 0, 0)'
                      }"
                    />
                    <YMapControls position="top left">
                      <YMapControl :transparent="true">
                        <div class="restriction_tooltip" v-html="RESTRICTION_TOOLTIP_TEXT"></div>
                      </YMapControl>
                    </YMapControls>
                  </YMap>
                `
                });
                App.mount('#app');
            }
            
            main();
        </script>

        <style> html, body, #app { width: 100%; height: 100%; margin: 0; padding: 0; font-family: Arial, Helvetica, sans-serif; } .toolbar { position: absolute; z-index: 1000; top: 0; left: 0; display: flex; align-items: center; padding: 16px; } .toolbar a { padding: 16px; }  </style>
        <link rel="stylesheet" href="./common.css" />
        <link rel="stylesheet" href="../variables.css" />
    </head>
    <body>
        <div id="app"></div>
    </body>
</html>
import type {LngLat, LngLatBounds, ZoomRange} from '@yandex/ymaps3-types';

// Bounding box - bottom left and top right corners
export const RESTRICT_AREA: LngLatBounds = [
    [38.9525, 51.5856],
    [39.4367, 51.7338]
];

export const POLYGON_COORDINATES: LngLat[] = [
    RESTRICT_AREA[0],
    [RESTRICT_AREA[1][0], RESTRICT_AREA[0][1]],
    RESTRICT_AREA[1],
    [RESTRICT_AREA[0][0], RESTRICT_AREA[1][1]]
];

export const ZOOM_RANGE: ZoomRange = {min: 12.45, max: 22};
:root {
}
import {ZOOM_RANGE} from './variables';

export const RESTRICTION_TOOLTIP_TEXT = `There is restriction over ${ZOOM_RANGE.min.toFixed()} zoom. <br/> To see border of restriction area move to sides.`;
.restriction_tooltip {
    padding: 8px 12px 8px 32px;
    border-radius: 12px;
    background-color: #313133;
    background-image: url('./info-icon.svg');
    background-position: 2% 20%;
    background-repeat: no-repeat;
    gap: 8px;
    color: #f2f5fa;
    font-size: 14px;
    line-height: 20px;
}