Adding objects with different geometries to the map.

Open in CodeSandbox

ObjectManager - A class for adding a large number of objects to the map without needing to create placemarks and add them to the map individually.

The objects added to ObjectManager are located in the ObjectManager.objects collection. The visual representation of placemarks and clusters are objects that implement the IOverlay interface. Overlays are placed in the ObjectManager.objects.overlays and ObjectManager.clusters.overlays collections, respectively.

ObjectManageraccepts placemark descriptions in JSON format. Placemarks can be clustered or shown as-is. If you don't use clusterization, the placemarks will be shown only in the visible map area. Since objects are stored in the manager as JSON descriptions and their visual representation is created only when necessary, this method of adding points to the map works faster than adding placemarks to the map directly or via the clusterer.

<!DOCTYPE html>
<html lang="en">
    <head>
        <title>
            Examples. Adding objects with different geometries to the map.
        </title>
        <meta charset="UTF-8" />

        <style>
            html,
            body,
            .map {
                width: 100%;
                height: 100%;
                margin: 0;
                padding: 0;
            }
        </style>
        <script src="https://yastatic.net/jquery/2.2.3/jquery.min.js"></script>
        <!--
        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/
    -->
        <script src="https://api-maps.yandex.ru/2.1/?lang=en_RU&amp;apikey=<your API-key>"></script>
        <script src="object_manager_spatial.js"></script>
    </head>
    <body>
        <div id="map" class="map"></div>
    </body>
</html>
ymaps.ready(function () {
    var map = new ymaps.Map("map", {
            center: [55.79, 37.64],
            zoom: 10,
            controls: ["zoomControl"],
        }),
        objectManager = new ymaps.ObjectManager();

    // Loading a GeoJSON file with object descriptions.
    $.getJSON("data.json").done(function (geoJson) {
        // Adding JSON object descriptions to the object manager.
        objectManager.add(geoJson);
        // Adding objects to the map.
        map.geoObjects.add(objectManager);
    });
});