单击事件触发两次

单击事件触发两次

本文介绍了Google Maps Api V3:单击事件触发两次的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在关注本页面中的MVCObject绑定示例:



我想要改变圆的颜色并在用户点击圆时切换标记的可见性,所以我将侦听器添加到RadiusWidget构造函数中,如下所示:



<$ p $ (){
strokeWeight:2
);;

this.set('distance',50);
this.bindTo('bounds',circle);
circle.bindTo('center',this);
circle.bindTo('map',this);
circle.bindTo('radius',this);
this.addSizer_();

google.maps.event.addListener(circle,'click',function()
{
alert('circle clicked');
});
}

我的问题是click事件正在触发TWICE。有谁知道为什么?

解决方案

我有类似的问题。它可能是地图API v3中的错误吗?我没有答案,只是一个解决方法:

  google.maps.event.addListener(circle,'click',function(事件){
if(event.alreadyCalled_){
alert('circle clicked');
}
else {
alert('首次点击的圆圈' );
event.alreadyCalled_ = true;
}
});

点击仍会触发两次,但您可以检测到。


I am following the MVCObject binding example from this page:

http://code.google.com/apis/maps/articles/mvcfun.html

I want to change the color of the circle and toggle the visibility of the markers when the user clicks on the circle, so I add the listener into the RadiusWidget constructor as follows:

function RadiusWidget() {
    var circle = new google.maps.Circle({
      strokeWeight: 2
    });

    this.set('distance', 50);
    this.bindTo('bounds', circle);
    circle.bindTo('center', this);
    circle.bindTo('map', this);
    circle.bindTo('radius', this);
    this.addSizer_();

    google.maps.event.addListener(circle, 'click', function()
    {
       alert('circle clicked');
    });
  }

My problem is that the click event is firing TWICE. Does anyone know why?

解决方案

I had a similar problem. Could it be a bug in maps API v3? I do not have an answer but a workaround:

google.maps.event.addListener(circle, 'click', function(event) {
    if (event.alreadyCalled_) {
        alert('circle clicked again');
    }
    else {
        alert('circle clicked first time');
        event.alreadyCalled_ = true;
    }
});

The click is still triggered twice but you can detect it.

这篇关于Google Maps Api V3:单击事件触发两次的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-09 21:10