2gisObjects

How to show many points on the map without freez

by dreamt

HTML

<div id="DGMap" class="loading" style="width:500px; height:400px"></div>

<a href="https://yadi.sk/i/0FuXA0OFkD6i5">Все точки</a>

JavaScript

<script src="http://maps.api.2gis.ru/2.0/loader.js?pkg=full"></script>
    <link rel="stylesheet" href="http://2gis.github.io/mapsapi/vendors/Leaflet.markerCluster/MarkerCluster.css" />
    <link rel="stylesheet" href="http://2gis.github.io/mapsapi/vendors/Leaflet.markerCluster/MarkerCluster.Default.css" />
    <script src="http://maps.api.2gis.ru/2.0/cluster_realworld.js"></script>
    
DG.then(function () {
            // загрузка кода модуля
            return DG.plugin('http://2gis.github.io/mapsapi/vendors/Leaflet.markerCluster/leaflet.markercluster-src.js');
        }).then(function () {
            map = DG.map('DGMap', {
                center: DG.latLng(54.92, 82.82),
                zoom: 9,
                geoclicker: true,
                //minZoom: 10,
                //maxZoom: 17
            });

            var markers = DG.markerClusterGroup({
                maxClusterRadius: 30,
                spiderfyDistanceMultiplier: 5
            });

            $.get('/Flat/JsonSearch', function(json) {
                var objects = json;
                map.setView([objects[0].Lattitude, objects[0].Longitude], 15);
                // обработка координат для установки маркеров
                $('#DGMap').removeClass('loading');
                var markers = createMarkers(objects);
                map.addLayer(markers);
            });



            map.on('moveend', function () {
                var isMoved = false;
                var coords = map.getBounds();
                var points;
                var points1 = [];
                points1.push(coords.getSouthWest().lat);
                points1.push(coords.getSouthWest().lng);
                points1.push(coords.getNorthEast().lat);
                points1.push(coords.getNorthEast().lng);


                var retrievedObject = localStorage.getItem('testObject');
                var storage = JSON.parse(retrievedObject);

                if (storage != null && storage.length > 0 && !isMoved) {
 ...