开发者

Google Maps Polyline CLICK Event

I'm implementing a map application. It uses Google Maps API for Flash. There is a one callback function that is triggered when the map is clicked. Additionally, there are plenty of polylines that are generated dynamically. The polylines have also click event listener assigned to them. The problem is when I click a polyline, the map click event is triggered at first and then the polyline's click event is fired.

I can't resolve that issue. It's really anoying. Here is code that assigns callback to the map's click event:

map = new Map();
map.key = GOOGLE_MAP_KEY;
map.addEventListener(MapMouseEvent.CLICK, onMapClicked, true);

and here is code that assigns callback function to a polyline's click event:

var polyline:Polyline = new Polyline(path);
polyline.addEventListener(MapMouseEvent.CLICK, cutToEnd);

I need to supress the "onMapClicked" function's invocation when I click on a polyline. Only "cutToEnd" method should be inv开发者_如何学Coked.

Thanks


map.addEventListener(MapMouseEvent.CLICK, onMapClicked, true);

You use bubblingPhase here (third "true" parameter). It means, that when you click polyline, event "reaches" first your map, because it's capturing from stage to your button. Set parameter "false", or leave only 2 parameters (useCapture is "false" by default). Then in the end of your polyline click handler add event.stopPropagation() method call. It will make event stop bubbling to stage, and it won't "reach" your map.

UDATE: If MapMouseEvent does not bubble you can compare event.target and event.currentTarget properties. In your polyline click listener they will be equal. So you may add

 if(event.target != event.currentTarget)
    return;

at the beginning of your map click listener.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜