1

我在 Bing 地图 API v7 中没有看到会显示双击事件的事件。有没有办法做到这一点?假设我没有错过本机支持,我想我将不得不编写自己的带有计时器的双击处理程序。

4

2 回答 2

4

如果你只使用双击事件

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

应该解决问题

于 2012-08-29T12:23:04.957 回答
4

点击事件也有问题。事实上,正常的点击事件也会在双击事件期间触发。这就是为什么我必须实现我自己的双击处理程序。我的方法可以翻译成右键单击,因为我只使用单击事件,鼠标右键也可用。

//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;
});
于 2012-12-01T12:53:45.963 回答