Select to view content in your preferred language

Click Map vs. Click Graphic

1082
3
05-05-2014 09:16 AM
AngusHenderson
Emerging Contributor
I am listening for MouseEvent.CLICK's on the main map:Map and several Graphics in a layer.

The problem is when i click a graphic I get both events in random order, so I cant reliably tell if it was a map click or graphic click

How can I get the graphic clicks to override the map clicks?

angus henderson
Tags (2)
0 Kudos
3 Replies
EvelynHernandez
Frequent Contributor
I remember to use only the click event on a map, and then u have to make a rectangular area and see if there is some graphic on it.
0 Kudos
AngusHenderson
Emerging Contributor
Thank you for the reply, I saw a similar technique in the javascript examples. A little more searching and i found that a map click event which started from a graphic has the graphic's symbol as the target, so I get event.target.parent as Graphic

  private static function mapMouseUpHandler(event:MouseEvent):void
  {
   if( _mouseDrag == false) {
    if (event.target.parent is Graphic)
    {
     var graphic:Graphic = event.target.parent as Graphic;
     var idx:int = int(graphic.attributes["Index"]);
     Tags.getInstance().onClickTag(idx);
     return;
    }
    var mouseMapPoint:MapPoint = map.toMapFromStage(event.stageX, event.stageY);
    var x:Number = mouseMapPoint.x;
    var y:Number = mouseMapPoint.y;
    mapLocationQuery(map, x, y);
   }
  }
0 Kudos
raffia
by
Deactivated User
I have come across the same exact situation. I found out that the identify method takes a lot more time than the graphic click. So this solution worked all the time. I set a var to values of zero and 1. 1 is assigned when the graphic is clicked. In my identify function, I check for the var value, if 1, then by pass the function and don't do anything, else, proceed with the identification.
0 Kudos