Google Maps Api V3:在某些缩放级别上限制 MarkerClusterer
我有一个 MarkerClusterer,如果缩放级别低于阈值,我想禁用它。
例子: 缩放级别为 10,簇可见。阈值为 5,因此如果用户缩小查看世界,则不应渲染所有标记。但我不想清除标记,因为如果用户再次放大,则需要显示它们。
I have a MarkerClusterer which i want to disable if the zoom level is below a threshold.
Example:
The zoom level is 10, the clusters are visible. The threshold is 5, so if the user zooms out to see the world, all Markers should not be rendered. I don't want to clear the markers though, because they need to be shown if the user zooms in again.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您不想清除标记,则可以使用 setMap() 将分配了 MarkerCluster 的地图设置为与用户正在查看的地图不同的地图。
setMap() 将
null
作为有效参数。另一种选择是进行一些糟糕的修改,例如创建用户不可见的第二个地图并将 MarkerCluster 分配给该地图。它不会赢得任何编码竞赛,但它会起作用。
然后,当您回到适当的缩放级别时,您可以再次使用 setMap() 将 MarkerCluster 放回到地图上。
您可以使用 Zoom_changed 事件来检测地图上的缩放何时发生更改,并相应地调用 setMap()。
希望这就是您完成此操作所需的全部内容,但如果没有,请发布您的一些代码,也许我们可以尝试更具体地说明如何修改它以实现此目的。
If you don't want to clear the markers, you can instead use setMap() to set the map, to which the MarkerCluster is assigned, to a different map than the one the user is viewing.
setMap() takes
null
as a valid parameter.Another option is to do some awful hack, like creating a second map that is not visible to the user and assigning the MarkerCluster to that map. It won't win any coding competitions, but it will work.
Then, when you get back to an appropriate zoom level, you can use setMap() again to put the MarkerCluster back on the map.
You can use the zoom_changed event to detect when the zoom on the map has changed and call setMap() appropriately.
Hopefully, this is all you need to get this done, but if not, post some of your code and maybe we can try to be more specific about exactly how to modify it to achieve this.