如何关闭所有弹出窗口? [英] How to close all popups?

查看:177
本文介绍了如何关闭所有弹出窗口?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的map上有多个(444)popups.

I have multiple (444) popups open on my map.

我尝试过:

$(".leaflet-popup-close-button").each(function (index) {
    $(".leaflet-popup-close-button")[index].click();
});

但是这样,并不是所有人都被关闭了.仅其中一半被删除.恰好一半.因此,第一次删除222,第二次删除111.

But this way, not all get closed. Only half of them get removed. Exactly half. So first time 222 get removed, the second time 111 get removed.

为什么会这样?

推荐答案

我知道您正在尝试做什么,但这似乎不是一个好主意.您实际上是(通过编程)引起了444次实际上并不存在的点击.如果有一天您决定跟踪用户对这些项目的点击,就会遇到问题.

I see what you're trying to do, but that doesn't seem to be a very good idea. You're literally (programmatically) causing 444 clicks that don't really exist to happen. If one day you decide to track user clicks on those items, you'll have a problem.

如果您尝试通过CSS将其添加到通过CSS折叠/关闭的444个leaflet-popup-close-button的公共父级中,该怎么办?

What if you try to add a class to the common parent of those 444 leaflet-popup-close-button that force them, via CSS to collapse/close?

类似的东西将是您要尝试做的更好的解决方案.

Something like that would be a better solution for what you're trying to do.

顺便说一句,检查他们的文档似乎这些弹出窗口都在新的窗口中打开了层,所以您可能只需要删除该层,所有这些都将消失.

Btw, checking their docs it seems like these popups are all open on a new layer, so you probably just need to remove that layer and all of them will be gone.

来自他们的文档:

使用Map#openPopup打开弹出窗口,同时确保一次只打开一个弹出窗口(出于可用性考虑,建议使用),或者使用Map#addLayer打开任意数量的窗口.

Use Map#openPopup to open popups while making sure that only one popup is open at one time (recommended for usability), or use Map#addLayer to open as many as you want.

并进一步检查您是否有addLayerremoveLayer.无论您做什么,我建议您都避免以编程方式进行所有这些点击.

And checking further you have addLayer and removeLayer. Whatever you do, I'd suggest you avoid all those programmatically clicks.

这篇关于如何关闭所有弹出窗口?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆