function zoom to cluster closes cluster with multiple markers at same lat/lng - Javascript Leaflet

Javascript examples for Leaflet:Marker

Description

function zoom to cluster closes cluster with multiple markers at same lat/lng

Demo Code

ResultView the demo in separate window

<html>
   <head> 
      <meta name="viewport" content="width=device-width, initial-scale=1"> 
      <script type="text/javascript" src="https://unpkg.com/leaflet@1.0.3/dist/leaflet-src.js"></script> 
      <link rel="stylesheet" type="text/css" href="https://unpkg.com/leaflet@1.0.3/dist/leaflet.css"> 
      <link rel="stylesheet" type="text/css" href="https://unpkg.com/leaflet.markercluster@1.0.4/dist/MarkerCluster.css"> 
      <link rel="stylesheet" type="text/css" href="https://unpkg.com/leaflet.markercluster@1.0.4/dist/MarkerCluster.Default.css"> 
      <script type="text/javascript" src="https://unpkg.com/leaflet.markercluster@1.0.4/dist/leaflet.markercluster-src.js"></script> 
      <style id="compiled-css" type="text/css">

#map {//from  w  ww . ja  va  2  s .  c  o m
   height: 500px;
}


      </style> 
      <script type="text/javascript">
    window.onload=function(){
var map = L.map("map");
L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
  attribution: '&copy; <a href="http://osm.org/copyright">OpenStreetMap</a> contributors'
}).addTo(map);
map.setView([48.85 - 0.03, 2.35 + 0.07], 12);
var mcg = L.markerClusterGroup().addTo(map);
for (var i = 0; i < 50; i += 1) {
  L.marker([48.85, 2.35]).addTo(mcg);
}
mcg.on('spiderfied', function (event) {
   var cluster = event.cluster;
   map.panTo(cluster.getLatLng());
});
function getRandomLatLng() {
  return [
    48.8 + 0.1 * Math.random(),
    2.25 + 0.2 * Math.random()
  ];
}
    }

      </script> 
   </head> 
   <body> 
      <div id="map"></div>  
   </body>
</html>

Related Tutorials