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

# Добавление геообъектов в коллекцию

<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/ru/geo_object_collection/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/x8nmlg?file=index.html">Open in CodeSandbox</a>

<div id="references">
    <a href="https://yandex.ru/dev/jsapi-v2-1/doc/ru/v2-1/ref/reference/ready">ready</a>,
    <a href="https://yandex.ru/dev/jsapi-v2-1/doc/ru/v2-1/ref/reference/Map">Map</a>,
    <a href="https://yandex.ru/dev/jsapi-v2-1/doc/ru/v2-1/ref/reference/Placemark">Placemark</a>,
    <a href="https://yandex.ru/dev/jsapi-v2-1/doc/ru/v2-1/ref/reference/GeoObjectCollection">GeoObjectCollection</a>
</div>
<p>
    Геообъекты можно объединять в коллекции. Вы можете создавать коллекции для групповых операций над геообъектами.
    Например, можно подписываться на события объектов или задавать им опции.
</p>

{% list tabs %}

-   index.html

    ```html
    <!DOCTYPE html>
    <html>
        <head>
            <title>Добавление геообъектов в коллекцию</title>
            <meta
                http-equiv="Content-Type"
                content="text/html; charset=utf-8"
            />
            <!--
            Укажите свой API-ключ. Тестовый ключ НЕ БУДЕТ работать на других сайтах.
            Получить ключ можно в Кабинете разработчика: https://developer.tech.yandex.ru/keys/
        -->
            
            
            
        </head>
        <body>
            <div id="map"></div>
        </body>
    </html>
    ```

-   geo_object_collection.js

    ```js
    ymaps.ready(init);

    function init() {
        var myMap = new ymaps.Map(
                "map",
                {
                    center: [55.73, 37.75],
                    zoom: 9,
                },
                {
                    searchControlProvider: "yandex#search",
                }
            ),
            yellowCollection = new ymaps.GeoObjectCollection(null, {
                preset: "islands#yellowIcon",
            }),
            blueCollection = new ymaps.GeoObjectCollection(null, {
                preset: "islands#blueIcon",
            }),
            yellowCoords = [
                [55.73, 37.75],
                [55.81, 37.75],
            ],
            blueCoords = [
                [55.73, 37.65],
                [55.81, 37.65],
            ];

        for (var i = 0, l = yellowCoords.length; i < l; i++) {
            yellowCollection.add(new ymaps.Placemark(yellowCoords[i]));
        }
        for (var i = 0, l = blueCoords.length; i < l; i++) {
            blueCollection.add(new ymaps.Placemark(blueCoords[i]));
        }

        myMap.geoObjects.add(yellowCollection).add(blueCollection);

        // Через коллекции можно подписываться на события дочерних элементов.
        yellowCollection.events.add("click", function () {
            alert("Кликнули по желтой метке");
        });
        blueCollection.events.add("click", function () {
            alert("Кликнули по синей метке");
        });

        // Через коллекции можно задавать опции дочерним элементам.
        blueCollection.options.set("preset", "islands#blueDotIcon");
    }
    ```

{% endlist %}
