用Bing地图检测鼠标右键

时间:2012-05-08 21:01:17

标签: bing-maps

我试图在Bing地图上捕获鼠标右键。我得到的只是浏览器上下文菜单(我想禁用它)。如何修改以下代码以使鼠标右键单击?

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
    <title></title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <script type="text/javascript" src="http://ecn.dev.virtualearth.net/mapcontrol/mapcontrol.ashx?v=7.0"></script>
    <script type="text/javascript">

        var map = null;

        function GetMap() {
            // Initialize the map
            map = new Microsoft.Maps.Map(document.getElementById("myMap"),
                         { credentials: "MyApiKey" });

            //Add handler for the map click event.
            Microsoft.Maps.Events.addHandler(map, 'click', function (e) {
                alert('click');
                if (e.isSecondary)
                    alert('rightclick');
            });
        }
    </script>
</head>
<body onload="GetMap();">
    <div id='myMap'>
    </div>
</body>
</html>

1 个答案:

答案 0 :(得分:1)

假设您使用的是v7,您可以在地图上注册rightclick事件:

   Microsoft.Maps.Events.addHandler(map, 'rightclick', function(e) {
        alert('click');
        if (e.isSecondary)
            alert('rightclick');
    });

要禁用浏览器上下文菜单,此问题已在此处得到解答:

Bing Maps V7 Context Menu

重新粘贴相关部分:

<body oncontextmenu="return false">
...
</body>