简体   繁体   中英

Google map clustering with batch wise data issue with zoom in or out time

//This is the code//
var mapDiv = document.getElementById('newmap');
map = new google.maps.Map(mapDiv, {
        center: new google.maps.LatLng(latitude, longitude),
        zoom: zoom,
        panControl: true,
        mapTypeControl: true,
        mapTypeControlOptions: {
        style: google.maps.MapTypeControlStyle.DROPDOWN_MENU
        },
        zoomControl: true,
        zoomControlOptions:
         {
          position: google.maps.ControlPosition.LEFT_TOP,

         },
        streetViewControl: true,
        mapTypeId: google.maps.MapTypeId.ROADMAP
    });
var new_arr=new Array();
function addMarker1(locations,outletname,outletData)
{
           var markers1 = locations.map(function(location, i)
            {
                 return new google.maps.Marker
                  ({
                      position: location,
                  });
            });
var markerCluster = new MarkerClusterer(map, new_arr,{imagePath: 'https://developers.google.com/maps/documentation/javascript/examples/markerclusterer/m'});
              new_arr=new_arr.concat(markers1);
              markerCluster.resetViewport();
              markerCluster.clearMarkers();
              markers = [];
              markerCluster.removeMarker(new_arr);
              markerCluster.addMarkers(new_arr);
              markerCluster.redraw();
}
// this is sending location in patches of 10000 each//
addMarker1(j,outletname,outletData);

The total data that needs to be rendered is 100000. I am sending data in patches of 10000 and concating it to display a final single cluster of 100000 markers which works correctly. But after zoom in when I click on zoom out it again forms patches of 10000 each on every zoom_changed event and overlaps by forming clusters of 10000 each instead of forming one single cluster.

The solution is to clear the data before looping through the markers

            if (markerCluster) 
            {
                  markerCluster.clearMarkers();
                  markerCluster.resetViewport();
                  markers = [];
                  markerCluster.removeMarker(new_arr);
            }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM