Removing old point cluster graphic

1081
6
04-23-2013 07:10 AM
BetsySchenck-Gardner
Occasional Contributor
Thanks to Derek's excellent example last week of using point clustering on a feature map, I've been able to implement this function into a map I'm developing. The only problem I can't figure out is how to dismiss an old point cluster and get a new one generated. I've looked at the ClusterLayer.js and saw a function called clear so I added that to my code ... clusterLayer.clear(). The cluster graphic gets removed but a new cluster graphic isn't generated. I just have a blank map with no clusters. I know I have values available for clustering because when I do a clusterLayer.length, I get a count of the records found.  It just won't generate a new cluster graphic. Has anyone tried to dismiss an old cluster graphic and get a new one?
0 Kudos
6 Replies
derekswingley1
Frequent Contributor
The cluster layer should be handling this for you, meaning that you shouldn't have to manually manage cluster graphics.

Clusters should be removed and regenerated when the map's zoom level changes. Is that not working for you?
0 Kudos
BetsySchenck-Gardner
Occasional Contributor
The cluster layer should be handling this for you, meaning that you shouldn't have to manually manage cluster graphics.

Clusters should be removed and regenerated when the map's zoom level changes. Is that not working for you?


The clusters are regenerated when I change my map's zoom level.  My issue lies in having a new query result.  For example, in my map, the user can enter the name of a species and the query task will come back with those results clustered. If the user enters a new query for a different species, the results come back but they aren't being displayed at all ... not as clusters or anything else. The old cluster results are still being displayed on the map.
0 Kudos
derekswingley1
Frequent Contributor
The clusters are regenerated when I change my map's zoom level.  My issue lies in having a new query result.  For example, in my map, the user can enter the name of a species and the query task will come back with those results clustered. If the user enters a new query for a different species, the results come back but they aren't being displayed at all ... not as clusters or anything else. The old cluster results are still being displayed on the map.


I understand, that's a slightly different issue. The cluster layer as-is expects all data initially and isn't set up to have new data continuously pushed in. One option would be to remove the cluster layer, destroy it and then create a new cluster layer when new data is available. It might also be possible to re-cluster on the fly, but I haven't looked at that code in a while so I'm not certain that re-clustering would be easy without changing some of the cluster layer's methods.
0 Kudos
BetsySchenck-Gardner
Occasional Contributor
I understand, that's a slightly different issue. The cluster layer as-is expects all data initially and isn't set up to have new data continuously pushed in. One option would be to remove the cluster layer, destroy it and then create a new cluster layer when new data is available. It might also be possible to re-cluster on the fly, but I haven't looked at that code in a while so I'm not certain that re-clustering would be easy without changing some of the cluster layer's methods.


Well finally figured it out. Instead of using clusterLayer.clear() which removed the cluster graphics but didn't allow for a new clustering of data, I used map.removeLayer(clusterLayer). That removed the graphic and allowed a new cluster to be generated. Thanks for your help Derek.
0 Kudos
derekswingley1
Frequent Contributor
Glad you got it sorted out!
0 Kudos
TyroneLigon
Occasional Contributor
I added the following public function to ClusterLayer.js:

refreshData: function(data) {
  this.clear();
  this._clusterData = data;
  this._clusterGraphics();
},


This permits you to refresh the data set and generate a new set of clusters. Now you don't need to destroy and re-create the cluster layer.

If the upper limit of the cluster layer's last renderer break is not set to "Infinity" you might need to delete and re-create the last break in the renderer.
0 Kudos