用Bing地图检测鼠标右键双击

时间:2012-05-09 17:04:22

标签: bing-maps

我没有在Bing map API v7中看到会出现双击事件的事件。有没有办法做到这一点?假设我没有错过本机支持,我想我必须用计时器编写自己的双击处理程序。

2 个答案:

答案 0 :(得分:4)

如果您只使用双击事件

Microsoft.Maps.Events.addHandler(this.map, 'dblclick', functionHandler)

应解决问题

答案 1 :(得分:4)

我也遇到了点击事件的问题。事实上,正常的点击事件也会在双击事件期间触发。这就是我必须实现自己的双击处理程序的原因。我的方法可以转换为rigth点击,因为我只使用单击事件,也可用于鼠标右键。

//Set up my Handler (of course every object can be the target)
Microsoft.Maps.Events.addHandler(map, 'click', Click);
//count variable, that counts the amount of clicks that belong together
myClick=0;

//A click fires this function
function click (e)
{
    //If it is the first click of a "series", than start the timeout after which the clicks are handled
    if (myClick == 0)
    {       
        //Target have to be buffered
        target= e;
        //accumulate the clicks for 200ms and react afterwards
        setTimeout("reaction(target)", 200);
    }
        //count the clicks
    myClick = myClick+1;
}

//At the end of timeout check how often a click has been performed and react
function reaction(e)
{
    if (myClick==1)
    {
        alert("Single Click!");
    }
    else (myClick==2)
    {
        alert("Double click!");
    }
        else (myClick==3)
        {
                alert("Tripple click");
        }
    //reset ClickCount to zero for the next clicks
    myClick = 0;
}

此外,删除Bing-Maps的标准双击行为可能会很有趣,可以放大。这可以通过以下代码实现:

Microsoft.Maps.Events.addHandler(map, 'dblclick', function(e){
      e.handled = true;
});