文档

Marker隐藏后,MarkerCluster工作不正常

https://lbs.amap.com/api/javascript-api/reference/plugin#AMap.MarkerClusterer

当把一个已经加入 MarkerCluster 的 Marker 隐藏后,发现 MarkerCluster 工作不正常了,具体表现为:

  1. 聚合数据没有随着Marker的隐藏而减少
  2. 无法点击 MarkerCluster;点击且报错 Cannot read properties of undefined (reading 'rR')

把需要隐藏的 Marker 从 MarkerCluster 移除,显示的是时候,再往 MarkerCluster 里添加。

// 隐藏
Marker.hide()
// 移除(以下三种方法根据实际情况使用)
MarkerCluster.clearMarkers() 移除所有
MarkerCluster.removeMarkers() 移除一组
MarkerCluster.removeMarker() 移除一个

// 显示
Marker.show()
// 往MarkerCluster添加Marker(以下两种方法根据实际情况使用)
MarkerCluster.addMarkers() 添加一组
MarkerCluster.addMarker() 添加一个