---
metadata:
  - name: generator
    content: Diplodoc Platform v5.39.1
alternate:
  - https://yandex.com/dev/jsapi-v2-1/doc/en/v2-1/examples/cases/geo_object_collection.md
  - https://yandex.com/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/dev/jsapi-v2-1/doc/en/llms.txt

# Adding geo objects to a collection

<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/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/fv7clm?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/Placemark">Placemark</a>,
    <a href="https://yandex.ru/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/GeoObjectCollection">GeoObjectCollection</a>
</div>
<p>
    Geo objects can be grouped into collections. You can create collections for group operations on geo objects.
    For example, you can subscribe to events of objects or set their options.
</p>

{% list tabs %}

-   index.html

    ```html
    <!DOCTYPE html>
    <html>
        <head>
            <title>Examples. Adding geo objects to a collection</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>
    ```

-   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);

        // You can subscribe to events of child elements through collections.
        yellowCollection.events.add("click", function () {
            alert("Yellow placemark clicked");
        });
        blueCollection.events.add("click", function () {
            alert("Blue placemark clicked");
        });

        // You can set options of child elements through collections.
        blueCollection.options.set("preset", "islands#blueDotIcon");
    }
    ```

{% endlist %}
