要更新所有 InfoWindow 弹窗的位置并移除旧位置的弹窗,你可以按照以下步骤进行操作:

  1. 首先,创建一个新的 OverlayPredicate 来过滤掉不需要的弹窗。在这个 OverlayPredicate 中,我们要检查每个 overlay 是否是 MyInfoWindow 类型,并且不包含在 markers 列表中。如果满足这两个条件,我们就需要移除这个旧的弹窗。

  2. 接下来,遍历所有的 overlay,并使用 OverlayManager 的 remove 方法来移除满足条件的旧弹窗。

  3. 最后,更新所有的 InfoWindow 弹窗的位置。

以下是示例代码:

OverlayPredicate overlayPredicate = new OverlayPredicate() {
    @Override
    public boolean evaluate(Overlay overlay) {
        return (overlay instanceof MyInfoWindow) && !markers.contains(((MyInfoWindow) overlay).getMarker());
    }
};

// 移除所有满足条件的旧弹窗
overlayManager.remove(overlayPredicate);

// 更新所有 InfoWindow 弹窗的位置
for (Overlay overlay : overlayManager) {
    if (overlay instanceof MyInfoWindow) {
        MyInfoWindow myInfoWindow = (MyInfoWindow) overlay;
        myInfoWindow.updatePosition();
    }
}

请确保在调用这段代码之前,你已经初始化了 overlayManager,并且 markers 列表包含了所有需要保留的标记。


原文地址: https://www.cveoy.top/t/topic/o3aI 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录