2

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);
1
  • map.addLayer(layer); what is layer?
    – L. Sanna
    Jun 4, 2013 at 20:53

1 Answer 1

3

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

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

});

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.