var map = null;
var mark = [];
var markers = [];
var markerCluster;
//Create cluster object.
var size = 50000; //set no. of markers in cluster.
window.onload = function () {
var center = new L.LatLng(28.7041, 77.1025);
markerCluster = new PruneClusterForLeaflet();
map = new MapmyIndia.Map('map-container', {
zoomControl: true,
hybrid: true,
center:center,
zoom: 15,
});
drawCluster(); //call drawCluster()
};
function drawCluster() {
clearCluster();
markerCluster.Cluster.showExactCount = false; //false will display rounded off marker's count in cluster. true will display exact count. Default true.
markerCluster.Cluster.Size = 150; //set the area of cluster. Higher number means more markers merged. Default 120.
for (var i = 0; i < size; i++) {
var marker = new PruneCluster.Marker(center.lat + (Math.random() - 0.5) * Math.random() * 0.00001 * size,
center.lng + (Math.random() - 0.5) * Math.random() * 0.00002 * size); //create prune cluster marker
marker.data.idx = i; //set custom data in marker.data object;
markers.push(marker); //add marker in custom array
markerCluster.RegisterMarker(marker); //Register marker as a member of cluster group.
}
//set custom marker icon
markerCluster.PrepareLeafletMarker = function (marker, data) {
marker.setIcon(L.icon({
iconUrl: "images/location.png",
iconSize: [21, 32]
}));
//tooltip on mouseover
marker.bindTooltip("Marker no. " + data.idx);
};
map.addLayer(markerCluster);
//fit map bound
markerCluster.FitBounds();
//ProcessView function must be called everytime cluster changes/updates.
markerCluster.ProcessView();
}
//handle overlapping markers
function createSpiderfyCluster() {
clearCluster();
markerCluster.Cluster.showExactCount = true; //false will display rounded off marker's count in cluster. true will display exact count. Default true.
markerCluster.Cluster.Size = 150; //set...
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.