Osmandroid: 更新所有 InfoWindow 弹窗位置并移除旧弹窗 - 代码示例
要更新所有 InfoWindow 弹窗的位置,首先需要获取当前所有的 InfoWindow 弹窗,并设置新的位置。然后,移除旧位置的 InfoWindow 弹窗。
以下是一个示例代码,演示如何更新所有 InfoWindow 弹窗的位置和移除旧位置的 InfoWindow 弹窗:
// 获取当前所有的 InfoWindow 弹窗
List<Marker> markers = mapView.getOverlays().stream()
.filter(overlay -> overlay instanceof Marker)
.map(overlay -> (Marker) overlay)
.collect(Collectors.toList());
// 更新所有 InfoWindow 弹窗的位置
for (Marker marker : markers) {
InfoWindow infoWindow = marker.getInfoWindow();
if (infoWindow != null) {
// 设置新的位置
infoWindow.open(marker, marker.getPosition(), 0, 0);
}
}
// 移除旧位置的 InfoWindow 弹窗
mapView.getOverlayManager().removeAll(new OverlayPredicate() {
@Override
public boolean evaluate(Overlay overlay) {
return (overlay instanceof InfoWindow) && !markers.contains(((InfoWindow) overlay).getMarker());
}
});
请注意,以上代码假设您已经将 osmdroid 库正确地集成到您的 Android 项目中,并且已经创建了一个 MapView 实例(名为 mapView)。另外,您可能需要根据您的具体需求进行一些适当的修改。
原文地址: https://www.cveoy.top/t/topic/o3ai 著作权归作者所有。请勿转载和采集!