Select to view content in your preferred language

mouse events with cluster symbols

949
3
09-21-2010 02:39 PM
DavidElies
Deactivated User
When using the GridClusterer, I'm trying to figure out how to get the mouse events on the clustered cluster graphics (as opposed to the expanded cluster graphics).  It must be possible, because the FlareSymbol responds to mouseovers.  I want to set the behavior when a user mouses over a CellSymbol, for example.  Can anyone help me?
Tags (2)
0 Kudos
3 Replies
DavidElies
Deactivated User
I'm partway there on a solution, but I don't think it's the best option.  I've used the MouseDown event for the whole FeatureLayer.  Then I grab the target of the event and cast it as a ClusterGraphic.  Like this:

protected function fLayer_mouseDownHandler(event:MouseEvent):void
{
 var gr:ClusterGraphic = ClusterGraphic(event.target);
 var grs:Array = gr.cluster.graphics;
 for each(var g in grs) {
 }
}

I don't have the flash debug player, so I can't tell what kind of errors or whatever I'm generating, but it appears to work fine, and I get access to all the graphics in the cluster (and more importantly, their attributes).

Can anyone tell me if there's a better or more efficient way to do this?  Otherwise, I guess this'll work fine.
0 Kudos
DavidElies
Deactivated User
It seems that graphicsLayers (and probably all layers) pass mouse event to their children so only the children respond.  I found that I can avoid errors by changing my code to

protected function fLayer_mouseDownHandler(event:MouseEvent):void
{
        if(event.target is ClusterGraphic) {
         var gr:ClusterGraphic = ClusterGraphic(event.target);
         var grs:Array = gr.cluster.graphics;
         for each(var g in grs) {
         }
        }
}


I'd still like to know if anybody has thoughts on a better way to do this.
0 Kudos
BrendanCollins
Deactivated User
I simply extend Symbol and get a reference to the ClusterGraphic by overriding the draw method.  Something like this...then use the symbol as the symbol for the graphicslayer's clusterer...this is

import com.esri.ags.Map;
import com.esri.ags.clusterers.supportClasses.ClusterGraphic;
import com.esri.ags.geometry.Geometry;
import com.esri.ags.symbols.Symbol;

import flash.display.Sprite;
import flash.events.MouseEvent;

public class MouseEventsClusterSymbol extends Symbol
{
  public function MouseEventsClusterSymbol()
  {
   super();
  }
 
  override public function draw(sprite:Sprite, geometry:Geometry, attributes:Object, map:Map):void
  {
   super.draw(sprite, geometry, attributes, map);
  
   const clusterGraphic:ClusterGraphic = sprite as ClusterGraphic;
   if(clusterGraphic)
   {
    clusterGraphic.addEventListener(MouseEvent.ROLL_OVER, graphicRollOverHandler);
    clusterGraphic.addEventListener(MouseEvent.ROLL_OUT, graphicRollOutHandler);
    clusterGraphic.addEventListener(MouseEvent.CLICK, graphicClickHandler);
   }
  
  }
 
  override public function clear(sprite:Sprite):void
  {
   super.clear(sprite);
  
   const clusterGraphic:ClusterGraphic = sprite as ClusterGraphic;
   if(clusterGraphic)
   {
    clusterGraphic.removeEventListener(MouseEvent.ROLL_OVER, graphicRollOverHandler);
    clusterGraphic.removeEventListener(MouseEvent.ROLL_OUT, graphicRollOutHandler);
    clusterGraphic.removeEventListener(MouseEvent.ROLL_OUT, graphicClickHandler);
   }
  }
}



Then use it in the GraphicsLayer's clusterer:

<esri:GraphicsLayer>
  <esri:clusterer>
   <esri:WeightedClusterer>
    <esri:symbol>
     <collections:MouseEventsClusterSymbol />
    </esri:symbol>
   </esri:WeightedClusterer>
  </esri:clusterer>
</esri:GraphicsLayer>


-------

I've been really digging AS3 Signals, so in my handlers, I send out a signal with a reference to the cluster graphic and handle the logic outside of the symbol itself...Hope this helps the cause.

Brendan
0 Kudos