OpenLayers 集群重新计算
因此,我有许多项目聚集在 OpenLayers 中。
我正在使用一种根据项目的属性对项目进行聚类的策略。
我更改项目的属性。
如何获取重新计算聚类的聚类策略?
So, I have a number of items clustered in OpenLayers.
I'm using a strategy that clusters the items based on their attributes.
I change an item's attribute.
How do I get the clustering strategy to recalculate the cluster?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
好的,事实证明,从 2.11RC1 开始,OpenLayers 中不提供此功能。因此,我自己将其实现为 Cluster 类的影子。该代码还可以作为 OpenLayers Trac 中的补丁提供。
本答案末尾的代码可以直接放入 JavaScript 文件中,并将覆盖现有的 OpenLayers
OpenLayers.Strategy.Cluster
类。它添加了一个方法recluster
,当调用该方法时,该方法将导致策略重新计算其聚类。由于我们正在更改Cluster
基类,因此任何派生类都应该适当地继承recluster
方法。如何使用它的一个示例是:
替换类的代码是:
Okay, so it turns out that this feature is not available in OpenLayers as of 2.11RC1. Therefore, I have implemented it as a shadow of the Cluster class myself. The code is also available as a patch in the OpenLayers Trac.
The code at the end of this answer can be dropped directly into a javascript file and will override the existing OpenLayers
OpenLayers.Strategy.Cluster
class. It adds a methodrecluster
which, when called, will cause the strategy to recalculate its clustering. Since we are altering theCluster
base class, any derived class should appropriately inherit therecluster
method.An example of how to use this would be:
The code for the replacement class is:
OpenLayers.Strategy.Cluster.cluster 方法仅在缩放事件或 cluster 对象不存在时重新计算。删除 cluster 对象并在 Cluster 对象上调用 cluster 。
OpenLayers.Strategy.Cluster.cluster method recalculate only if it is a zoomechanged event or clusters object does not exist. remove the clusters object and call cluster on Cluster object.