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

# Rectangle

<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/rectangle/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/s3pmgj?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/GeoObject">GeoObject</a>,
    <a href="https://yandex.ru/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/Rectangle">Rectangle</a>,
    <a href="https://yandex.ru/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/map.GeoObjects">map.GeoObjects</a>
</div>
<p>
   A rectangle can be created in two ways: using the <a href="https://yandex.ru/dev/jsapi-v2-1/doc/en/v2-1/dg/concepts/geoobjects">GeoObject</a> class
    indicating the "Rectangle" geometry type,
or using an auxiliary <a href="https://yandex.ru/dev/jsapi-v2-1/doc/en/v2-1/dg/concepts/geoobjects#geometry">Rectangle</a> class.
</p>
<p>
    When creating a rectangle, you must specify the coordinates of two opposite vertices. You may also specify its <a href="https://yandex.ru/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/GeoObject#constructor-summary">properties</a> (for example, the contents of its balloon or hint) and <a href="https://yandex.ru/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/GeoObject#constructor-summary">options</a> (such as fill color).
</p>
<p>
  Rectangles can be combined in a <a href="https://yandex.ru/dev/jsapi-v2-1/doc/en/v2-1/dg/concepts/geoobjects#geoobject_collections">collection</a>.
</p>

{% list tabs %}

-   index.html

    ```html
    <!DOCTYPE html>
    <html>
        <head>
            <title>Examples. Rectangle</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>
    ```

-   rectangle.js

    ```js
    ymaps.ready(init);
    var myMap, myGeoObject, myRectangle;

    function init() {
        myMap = new ymaps.Map(
            "map",
            {
                center: [55.674, 37.601],
                zoom: 11,
            },
            {
                searchControlProvider: "yandex#search",
            }
        );

        // Creating a geo object with the "rectangle" geometry type.
        myGeoObject = new ymaps.GeoObject(
            {
                // Geometry = geometry type + the coordinates of the geo object.
                geometry: {
                    // The geometry type is rectangle.
                    type: "Rectangle",
                    // The coordinates.
                    coordinates: [
                        [55.665, 37.66],
                        [55.64, 37.53],
                    ],
                },
                // Properties.
                properties: {
                    hintContent: "Drag me!",
                    balloonContent: "Rectangle 2",
                },
            },
            {
                /**
                 * Options.
                 *  The object can be dragged.
                 */
                draggable: true,
                // The fill color and transparency.
                fillColor: "#ffff0022",
                // The color and transparency of borders.
                strokeColor: "#3caa3c88",
                // Line width.
                strokeWidth: 7,
            }
        );

        // Creating a rectangle using an auxiliary class.
        myRectangle = new ymaps.Rectangle(
            [
                // Setting the coordinates of the diagonal corners of the rectangle.
                [55.66, 37.6],
                [55.71, 37.69],
            ],
            {
                //Properties
                hintContent: "You can't drag me!",
                balloonContent: "Rectangle 1",
            },
            {
                /**
                 * Options.
                 *  The fill color and transparency.
                 */
                fillColor: "#7df9ff33",
                /**
                 * Additional fill transparency.
                 *  The resulting transparency will not be #33(0.2), but 0.1(0.2*0.5).
                 */
                fillOpacity: 0.5,
                // Stroke color.
                strokeColor: "#0000FF",
                // Stroke transparency.
                strokeOpacity: 0.5,
                // Line width.
                strokeWidth: 2,
                /**
                 * The radius of rounded corners.
                 *  This option is accepted only for a rectangle.
                 */
                borderRadius: 6,
            }
        );

        myMap.geoObjects.add(myRectangle).add(myGeoObject);
    }
    ```

{% endlist %}
