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

# Creating a menu for displaying groups of 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/ymapsml_menu/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/7qf5xh?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/geoXml.load">geoXml.load</a>, <a href="https://yandex.ru/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/GeoObjectCollection">GeoObjectCollection</a>
</div>
<p>
    <a href="https://yandex.ru/dev/maps/ymapsml/doc/en/guide/concepts/About">YMapsML</a> is a language for describing geographical objects.
</p>
<p>
    In YMapsML, each geographical object is associated with a geometric shape
	and a geo object that is used for displaying this shape on the map. The shape definitions and their anchors to geographical coordinates are set in
	corresponding YMapsML elements. The <a href="https://yandex.ru/dev/maps/ymapsml/doc/en/ref/reference/gml-Point">gml:Point</a> element is designated for the "point" shape.
</p>
<p>
    The visual appearance of displayed objects is set in the
	<a href="https://yandex.ru/dev/maps/ymapsml/doc/en/ref/reference/representation-Representation">repr:Representation</a> element.
	For detailed instructions on setting styles for displayed objects,
	see the <a href="https://yandex.ru/dev/maps/ymapsml/doc/en/guide/concepts/styles-docpage/">documentation</a>.
</p>
<p>
    Use the <a href="https://yandex.ru/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/geoXml.load">geoXml.load</a> function for loading YMapsML data. After data is loaded, the function converts it to
    <a href="https://yandex.ru/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/GeoObjectCollection">GeoObjectCollection</a> and passes it to the handler function as a parameter.
</p>

{% list tabs %}

-   index.html

    ```html
    <!DOCTYPE html>
    <html>
        <head>
            <title>
                YMapsML examples. Creating a menu for displaying groups of
                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>
                <ul id="menu"></ul>
            </div>
            <div id="map"></div>
        </body>
    </html>
    ```

-   ymapsml_menu.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: 12,
            controls: [],
        });

        // Loading a YMapsML file.
        ymaps.geoXml.load("data.xml").then(
            function (res) {
                res.geoObjects.each(function (item) {
                    addMenuItem(item, myMap);
                });
            },
            // Called if loading the YMapsML file was unsuccessful.
            function (error) {
                alert(
                    "When loading the YMapsML file, the following error occurred: " +
                        error
                );
            }
        );

        // Adding an element to the list.
        function addMenuItem(group, map) {
            // Showing/hiding a group of geo objects on the map.
            $(
                '<a class="title" href="#">' +
                    group.properties.get("name") +
                    "</a>"
            )
                .bind("click", function () {
                    var link = $(this);
                    /**
                     * If the menu item is "inactive," we add the group to the map.
                     * Otherwise, we delete it from the map.
                     */
                    if (link.hasClass("active")) {
                        map.geoObjects.remove(group);
                    } else {
                        map.geoObjects.add(group);
                    }
                    // Changing the "active" state of the menu item.
                    link.toggleClass("active");
                    return false;
                })
                // Adding a new menu item to the list.
                .appendTo($("<li></li>").appendTo($("#menu")));
        }
    }
    ```

{% endlist %}
