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

# Getting the list of map objects

<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/object_list/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/5clp29?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/GeoObjectCollection">GeoObjectCollection</a>,
    <a href="https://yandex.ru/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/Placemark">Placemark</a>
</div>
<p>
   The example demonstrates how to create a menu to display collections of geo objects on the map.
</p>
<p>
   To create such a menu, you must create two representations of a geo object: its API-representation (in the form of placemarks on the map)
   and its DOM representation (i.e. the menu item).
</p>
<p>
   These representations can be linked inside the event handler for the DOM representation (click on menu item)
   by calling specific methods in the API representation of the geo object (adding/removing placemarks on the map).
</p>
<p>
   In this example, the menu is based on the data array that is defined in the file groups.js.
</p>
<p>
   The example is discussed more in the <a href="https://yandex.ru/blog/mapsapi/26637">developers' club</a>.
</p>

{% list tabs %}

-   index.html

    ```html
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
        <head>
            <title>Examples. A list of map objects.</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>
    ```

-   groups.js

    ```js
    // Groups of objects
    var groups = [
        {
            name: "Famous monuments",
            style: "islands#redIcon",
            items: [
                {
                    center: [50.426472, 30.563022],
                    name: "Monument &quot;Motherland&quot;",
                },
                {
                    center: [50.45351, 30.516489],
                    name: "Monument &quot;Bogdan Khmelnitsky&quot;",
                },
                {
                    center: [50.454433, 30.529874],
                    name: "Druzhby Narodov Arch",
                },
            ],
        },
        {
            name: "Pokushaiki",
            style: "islands#greenIcon",
            items: [
                {
                    center: [50.50955, 30.60791],
                    name: "Restaurant &quot;Kalinka-Malinka&quot;",
                },
                {
                    center: [50.429083, 30.521708],
                    name: "Bar &quot;Salo-bar&quot;",
                },
                {
                    center: [50.450843, 30.498271],
                    name: "Absinthe bar  &quot;Palata No. 6&quot;",
                },
                {
                    center: [50.454834, 30.516498],
                    name: "Restaraunt &quot;Spotykach&quot;",
                },
            ],
        },
        {
            name: "Original museums",
            style: "islands#orangeIcon",
            items: [
                {
                    center: [50.443334, 30.520163],
                    name: "The Museum of gramophones and vintage musical instruments",
                },
                {
                    center: [50.446977, 30.505269],
                    name: "Museum of the history of medicine or Anatomical theater",
                },
                {
                    center: [50.452512, 30.530889],
                    name: "The Museum of water. Water information center",
                },
            ],
        },
        {
            name: "Goodies",
            style: "islands#blueIcon",
            items: [
                {
                    center: [50.45987, 30.516174],
                    name: "The castle of Richard the Lion-heart",
                },
                {
                    center: [50.445049, 30.528598],
                    name: "&quot;House with chimeras&quot;",
                },
                {
                    center: [50.449156, 30.511809],
                    name: "The House Of Knight",
                },
            ],
        },
    ];
    ```

-   object_list.js

    ```js
    ymaps.ready(init);

    function init() {
        // Creating an instance of the map.
        var myMap = new ymaps.Map(
                "map",
                {
                    center: [50.443705, 30.530946],
                    zoom: 14,
                },
                {
                    searchControlProvider: "yandex#search",
                }
            ),
            // The container for the menu.
            menu = $('<ul class="menu"/>');

        for (var i = 0, l = groups.length; i < l; i++) {
            createMenuGroup(groups[i]);
        }

        function createMenuGroup(group) {
            // A menu item.
            var menuItem = $('<li><a href="#">' + group.name + "</a></li>"),
                // Collection for geo objects in a group.
                collection = new ymaps.GeoObjectCollection(null, {
                    preset: group.style,
                }),
                // The container for the submenu.
                submenu = $('<ul class="submenu"/>');

            // Adding a collection to the map.
            myMap.geoObjects.add(collection);
            // Adding a submenu.
            menuItem
                .append(submenu)
                // Adding a menu item.
                .appendTo(menu)
                // On click, removing/adding the collection to the map and hiding/displaying the submenu.
                .find("a")
                .bind("click", function () {
                    if (collection.getParent()) {
                        myMap.geoObjects.remove(collection);
                        submenu.hide();
                    } else {
                        myMap.geoObjects.add(collection);
                        submenu.show();
                    }
                });
            for (var j = 0, m = group.items.length; j < m; j++) {
                createSubMenu(group.items[j], collection, submenu);
            }
        }

        function createSubMenu(item, collection, submenu) {
            // A submenu item.
            var submenuItem = $('<li><a href="#">' + item.name + "</a></li>"),
                // Creating a placemark.
                placemark = new ymaps.Placemark(item.center, {
                    balloonContent: item.name,
                });

            // Adding a placemark to the collection.
            collection.add(placemark);
            // Adding an item to the submenu.
            submenuItem
                .appendTo(submenu)
                // When an item in the submenu is clicked, we open/close the placemark balloon.
                .find("a")
                .bind("click", function () {
                    if (!placemark.balloon.isOpen()) {
                        placemark.balloon.open();
                    } else {
                        placemark.balloon.close();
                    }
                    return false;
                });
        }

        // Adding the menu to the BODY tag.
        menu.appendTo($("body"));
        // Setting the map zoom so all groups are visible.
        myMap.setBounds(myMap.geoObjects.getBounds());
    }
    ```

{% endlist %}
