With the markerClusterGroup leaflet plugin, calling the spiderfy function twice automatically closes the opened popup.
This seems to be due to this piece of code in the unspiderfy
function, that is called automatically by the second spiderfy
call.
var tiles = L.tileLayer(...);
var map = L.map(...);
var coords = Array(...);
var mcg = L.markerClusterGroup();
var markers = Array();
for (var i = 0; i < 100; i++) {
var c = coords[i];
var marker = L.marker(new L.LatLng(a[0], a[1]));
markers.push(marker)
marker.bindPopup("Point " + i);
mcg.addLayer(marker);
}
function openPoint(i) {
var marker = markers[i];
var cluster = mcg.getVisibleParent(marker);
if(cluster && cluster.spiderfy) {
cluster.spiderfy();
}
}
map.addLayer(mcg);
var x = ...;
var y = ...;
openPoint(x) // Spiderfies the point x
markers[x].openPopup(); // Opens the popup for the point x
openPoint(y) // Spiderfies the point y, and sadly closes the previous popup
Here is a fiddle that illustrates the behavior I describe. Just click on buttons to spiderfy groups of items. Open a popup. And then click on another button to spiderfy another group of items. And see that the popup is closing.
How can I prevent this behavior?