[英]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);
需要渲染的總數據為100000。我以10000的補丁發送數據,並對其進行匯總以顯示最終正常工作的100000個標記的單個群集。 但是在放大后,當我單擊縮小時,它會在每個zoom_changed事件上再次形成每個10000的補丁,並通過形成每個10000的簇而不是形成一個單獨的簇來重疊。
解決方案是在遍歷標記之前清除數據
if (markerCluster)
{
markerCluster.clearMarkers();
markerCluster.resetViewport();
markers = [];
markerCluster.removeMarker(new_arr);
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.