John Livermore
John Livermore

Reputation: 31313

detecting right mouse click with Bing maps

I am trying to capture a right mouse click on a Bing map. All I get is the browser context menu (which I want to disable). How do I modify the following code to make the right mouse click work?

<!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>

Upvotes: 1

Views: 2249

Answers (1)

Bojin Li
Bojin Li

Reputation: 5799

Assuming you are using v7, there is a rightclick Event on the Map you can register with:

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

To disable the browser context menu, that question is already answered here:

Bing Maps V7 Context Menu

with the relevant parts re-pasted below:

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

Upvotes: 1

Related Questions