Select to view content in your preferred language

get clusters from clusterer

718
4
12-12-2011 05:35 AM
JamesSchlafley
Emerging Contributor
How do you get the clusters from a clusterer....to determine if certain graphics are within a cluster or not?  GraphicsLayer and Clusterer do not have a property or method to get the clusters currently drawn.
Tags (2)
0 Kudos
4 Replies
DasaPaddock
Esri Regular Contributor
If you iterate over the graphics in the graphics layer, the clusters are instances of ClusterGraphic. See:
http://help.arcgis.com/en/webapi/flex/apiref/com/esri/ags/clusterers/supportClasses/ClusterGraphic.h...
0 Kudos
JamesSchlafley
Emerging Contributor
Have you tried this?  I looped over all graphics in a graphicsLayer and they all returned as "Graphic" with the following statement...

Alert.show(flash.utils.getQualifiedClassName(myGraphicsLayer.graphicProvider).toString());

I expected this to return "ClusterGraphic" for some of the graphics.
0 Kudos
DasaPaddock
Esri Regular Contributor
The graphicProvider is unaffected by the clustering.

Try this:

for (var i:int = 0, n:int = myGraphicsLayer.numChildren; i < n; i++) 
{
    var graphic:Graphic = myGraphicsLayer.getChildAt(i) as Graphic;
    if (graphic is ClusterGraphic)
    {
        trace(graphic);
    }
}
0 Kudos
BrendanCollins
Deactivated User
One thing you can do is to subclass Symbol and add additional listeners in the draw method (but make sure you also remove them in the clear method).  I started with Mansour's attribute clusterer found here. In the AttrClusterSymbol.as draw method, you can add:

override public function draw(sprite:Sprite, geometry:Geometry, attributes:Object, map:Map):void
    {
        const clusterGraphic:ClusterGraphic = sprite as ClusterGraphic;
  clusterGraphic.addEventListener(MouseEvent.ROLL_OVER, graphicRollOverHandler);
  clusterGraphic.addEventListener(MouseEvent.ROLL_OUT, graphicRollOutHandler);
  clusterGraphic.addEventListener(MouseEvent.CLICK, graphicClickHandler);

........
}

you can then get the cluster.graphics off of the clusterGraphic when the user interacts with it.

Not sure if this will solve your problem, but it work well for me.

Again, just remember to remove these listeners in the clear method so don't you have crazy leaks.

-Brendan
0 Kudos