Javascript 传单和MarkerCluster-don';当当前有打开的弹出窗口时,是否执行群集?

Javascript 传单和MarkerCluster-don';当当前有打开的弹出窗口时,是否执行群集?,javascript,leaflet,leaflet.markercluster,Javascript,Leaflet,Leaflet.markercluster,我有一个传单+MarkerCluster应用程序,它在地图上有一些标记,并且在打开与标记相关联的弹出窗口(单击标记)时,有一些逻辑将图像覆盖添加到地图上。我使用bindpoop()将弹出窗口添加到标记中 markers.on('popupopen', function (e) { var b = e.layer.boundary; if (b) { //take some parameters for the overlay from an array that i

我有一个传单+MarkerCluster应用程序,它在地图上有一些标记,并且在打开与标记相关联的弹出窗口(单击标记)时,有一些逻辑将图像覆盖添加到地图上。我使用
bindpoop()
将弹出窗口添加到标记中

markers.on('popupopen', function (e) {

    var b = e.layer.boundary;

    if (b) {

    //take some parameters for the overlay from an array that is passed as a
    //property of the marker

    var image = b[0];
    var LatStart = b[1];
    var LngStart = b[2];
    var LatEnd = b[3];
    var LngEnd = b[4];

//doOverlay() creates the overlay
var overlay = doOverlay(image,LatStart,LngStart,LatEnd,LngEnd);

//add the overlay to the map
map.addLayer(overlay);

//make the overlay widely-accessible as a window property
window.overlay = overlay;

}
doOverlay()包含一些创建ImageOverlay的基本逻辑:

function doOverlay(image,LatStart,LngStart,LatEnd,LngEnd) {

  var bounds = new L.LatLngBounds (

  new L.LatLng(LatStart,LngStart),
  new L.LatLng(LatEnd,LngEnd));

var overlay = new L.ImageOverlay(image,
  bounds, {  
  pane: 'general'
});

    return overlay
}
但是,因为我正在使用MarkerCluster对集群中的标记进行分组,如果用户单击一个标记,获得弹出窗口并创建覆盖,然后他们缩小,就会发生集群,标记被集群,弹出窗口消失(,但不会生成popupclose事件)最后,我们在地图上得到了一个无法移除的重影图像覆盖

在正常情况下,当用户关闭弹出窗口(或单击地图或其他标记上的其他位置)时,将生成“popupclose”事件,我将删除图像层:

markers.on('popupclose', removeOverlay);

function removeOverlay() {

  if (window.overlay) {

  map.removeLayer(overlay);
  window.overlay=null;

  }
目前,我被迫监听每个“animationend”事件(当MarkerCluster在地图上任何位置控制的簇发生任何变化时),然后移除层并关闭弹出窗口,这是一种非常糟糕的方法,因为用户在准备好缩放设置时必须再次单击标记:

markers.on('animationend', function (e) {

    removeOverlay();

    map.closePopup();

});

如果您希望您的标记及其弹出窗口保留在地图上,并且不再由MarkerClusterGroup处理,那么一个简单的解决方案是在标记单击时将其从该组中删除(并将其直接添加到地图+打开弹出窗口)

然后,当弹出窗口关闭时,将标记添加回您的MarkerClusterGroup(首先将其从地图中删除;如果标记集群被认为是可见的,则将其添加回)


至于丢失的“popupclose”事件,这确实可能是一个问题,需要报告给传单.markercluster或传单。

你能给我一个如何做的小例子吗,因为只需从markercluster组中
removeLayer()
,然后
addLayer()
映射+
openPopup())
上面的代码似乎不起作用?我找到了一个很好的例子来说明如何做到这一点:。谢谢你给我指明了正确的方向。