[GIS] Leaflet Marker Cluster: Popups won’t open after first

clusteringleafletpopup

I built a map using Leaflet and markercluster.js, and I'm having a strange issue where after I click on the first popup, I'm unable to open any other popup. This happens whether you close the first popup manually or not.

When I don't use markercluster.js, the popups appear as normal, so I know it has something to do with that library. This is the second time I have used this library; the first time I had no issues. I'm getting no errors in the console.

Also, I had this issue regardless of if the .openPopup() method was attached to the marker variable.

Code below:

var puetrasList = new L.MarkerClusterGroup();

          for (i=0 ; i < dataStore.length ; i++){
              var a, point;
              a = dataStore[i];
              lat = parseFloat(dataStore[i][0]);
              lng = parseFloat(dataStore[i][1]);
              title = "<strong><h2>" + dataStore[i][2] + "</strong></h2>" +
                                  "<p>" + >dataStore[i][3] + "</p>" +
                                  "<p>" + >dataStore[i][4] + ", " + dataStore[i][5] + "</p>" +
                                  "<p>" + >dataStore[i][6] + "</p>";
              marker = new L.Marker(new L.LatLng(lat, lng));
              marker.bindPopup(title).openPopup();
              console.log(marker)
              puetrasList.addLayer(marker);
          }



          //----- Summon Map ---->
          map.addLayer(puetrasList);
          map.addLayer(layer);

Best Answer

Use marker on click in the for loop.It will shows the popup

 marker.on('click', function (e) {              
    this.bindPopup(title); 

});