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

# Filtering objects by various attributes

<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/geoobjects_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/fx77nj?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/geoQuery">geoQuery</a>,
    <a href="https://yandex.ru/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/GeoQueryResult">GeoQueryResult</a>
</div>
<p>
    You can use the <a href="https://yandex.ru/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/GeoQueryResult">GeoQueryResult</a> class to create a set of placemarks on the map from JSON descriptions of their geometries.
</p>
<p>
    The <a href="https://yandex.ru/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/GeoQueryResult#search">search</a> method allows you to filter the objects in the selection according to various criteria.
    For example, to select objects with a specific value in data fields or select objects based on the geometry type.
</p>
<p>
    This example shows how to select geo objects by multiple characteristics, and make a combination or a sample of the selection.
</p>

{% list tabs %}

-   index.html

    ```html
      <!DOCTYPE html>

    <html>

    <head>
        <title>Examples. Filtering objects by attributes.</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>
        <div style="padding: 5px;">
            <div>
                Filter by color <br>
                <input type="checkbox" id="red" checked="true">Red</input><br>
                <input type="checkbox" id="green" checked="true">Green</input><br>
                <input type="checkbox" id="yellow" checked="true">Yellow</input>
            </div>
            <div>
                Filter by geometries <br>
                <input type="checkbox" id="point" checked="true">Points</input><br>
                <input type="checkbox" id="polygon" checked="true">Polygons</input><br>
                <input type="checkbox" id="circle" checked="true">Circles</input>
            </div>
        </div>
    </body>
    </html>

    ```

-   geoobjects_menu.js

    ```js
    ymaps.ready(init);

    function init() {
        var myMap = new ymaps.Map(
            "map",
            {
                center: [55.30954, 37.721587],
                zoom: 8,
            },
            {
                searchControlProvider: "yandex#search",
            }
        );

        /**
         * A function, which according to the state of the checkboxes in the menu
         * shows or hides the geo objects from the selection.
         */
        function checkState() {
            var shownObjects,
                byColor = new ymaps.GeoQueryResult(),
                byShape = new ymaps.GeoQueryResult();

            // Selecting objects by color.
            if ($("#red").prop("checked")) {
                /**
                 * We will search using two parameters:
                 * - for point objects using the "preset" field;
                 * - for contour objects using the fill color.
                 */
                byColor = myObjects
                    .search('options.fillColor = "#ff1000"')
                    .add(
                        myObjects.search('options.preset = "islands#redIcon"')
                    );
            }
            if ($("#green").prop("checked")) {
                byColor = myObjects
                    .search('options.fillColor = "#00ff00"')
                    .add(
                        myObjects.search('options.preset = "islands#greenIcon"')
                    )
                    /**
                     * After we have found all the green objects, we will add them
                     * to the objects found in the previous iteration.
                     */
                    .add(byColor);
            }
            if ($("#yellow").prop("checked")) {
                byColor = myObjects
                    .search('options.fillColor = "#ffcc00"')
                    .add(
                        myObjects.search(
                            'options.preset = "islands#yellowIcon"'
                        )
                    )
                    .add(byColor);
            }
            // Selecting objects based on shape.
            if ($("#point").prop("checked")) {
                byShape = myObjects.search('geometry.type = "Point"');
            }
            if ($("#polygon").prop("checked")) {
                byShape = myObjects
                    .search('geometry.type = "Polygon"')
                    .add(byShape);
            }
            if ($("#circle").prop("checked")) {
                byShape = myObjects
                    .search('geometry.type = "Circle"')
                    .add(byShape);
            }

            /**
             * We selected objects by color and shape. Now we'll show objects on the map
             * that combine the desired characteristics.
             */
            shownObjects = byColor.intersect(byShape).addToMap(myMap);
            // Objects that were not included in the selection must be removed from the map.
            myObjects.remove(shownObjects).removeFromMap(myMap);
        }

        $("#red").click(checkState);
        $("#green").click(checkState);
        $("#yellow").click(checkState);
        $("#point").click(checkState);
        $("#polygon").click(checkState);
        $("#circle").click(checkState);

        // Creating objects from their JSON descriptions and adding them to the map.
        window.myObjects = ymaps
            .geoQuery({
                type: "FeatureCollection",
                features: [
                    {
                        type: "Feature",
                        geometry: {
                            type: "Point",
                            coordinates: [55.34954, 37.721587],
                        },
                        options: {
                            preset: "islands#yellowIcon",
                        },
                    },
                    {
                        type: "Feature",
                        geometry: {
                            type: "Circle",
                            coordinates: [55.24954, 37.5],
                            radius: 20000,
                        },
                        options: {
                            fillColor: "#ffcc00",
                        },
                    },
                    {
                        type: "Feature",
                        geometry: {
                            type: "Polygon",
                            coordinates: [
                                [
                                    [55.33954, 37.7],
                                    [55.43954, 37.7],
                                    [55.33954, 38.7],
                                    [55.33954, 37.7],
                                ],
                            ],
                        },
                        options: {
                            fillColor: "#ffcc00",
                        },
                    },
                    {
                        type: "Feature",
                        geometry: {
                            type: "Point",
                            coordinates: [55.24954, 37.4],
                        },
                        options: {
                            preset: "islands#greenIcon",
                        },
                    },
                    {
                        type: "Feature",
                        geometry: {
                            type: "Circle",
                            coordinates: [55.14954, 37.61587],
                            radius: 10000,
                        },
                        options: {
                            fillColor: "#00ff00",
                        },
                    },
                    {
                        type: "Feature",
                        geometry: {
                            type: "Point",
                            coordinates: [55.14954, 37.61587],
                            radius: 10000,
                        },
                        options: {
                            preset: "islands#redIcon",
                        },
                    },
                ],
            })
            .addToMap(myMap);
    }
    ```

{% endlist %}
