Export (0) Print
Expand All

MouseEventArgs Object

Bing

Contains the arguments for mouse events.

Properties

Name Type Description

eventName

string

The event that occurred.

handled

boolean

A boolean indicating whether the event is handled. If this property is set to true, the default map control behavior for the event is cancelled.

isPrimary

boolean

A boolean indicating if the primary button (such as the left mouse button or a tap on a touch screen) was used.

isSecondary

boolean

A boolean indicating if the secondary mouse button (such as the right mouse button) was used.

isTouchEvent

boolean

A boolean indicating whether the event that occurred was a touch event.

originalEvent

object

The original browser event.

pageX

number

The x-value of the pixel coordinate on the page of the mouse cursor.

pageY

number

The y-value of the pixel coordinate on the page of the mouse cursor.

target

object

The object that fired the event.

targetType

string

The type of the object that fired the event. Valid values include the following: ‘map’, ‘polygon’, ‘polyline’, or ‘pushpin’

wheelDelta

number

The number of units that the mouse wheel has changed.

Methods

Name Definition Return Value Description

getX

getX()

number

Returns the x-value of the pixel coordinate, relative to the map, of the mouse.

getY

getY()

number

Returns the y-value of the pixel coordinate, relative to the map, of the mouse.

Example

<!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:"Bing Maps Key"}); 

            //Add handler for the map click event.
            Microsoft.Maps.Events.addHandler(map, 'click', displayEventInfo);

         }

          function displayEventInfo(e) {
              if (e.targetType == "map") {
                  var point = new Microsoft.Maps.Point(e.getX(), e.getY());
                  var loc = e.target.tryPixelToLocation(point);
                  document.getElementById("textBox").value = loc.latitude + ", " + loc.longitude;

              }
          }

      </script>
   </head>
   <body onload="GetMap();">
      <div id='myMap' style="position:relative; width:400px; height:400px;"></div><br>
      <b>Click the map to display the coordinate values at that point.</b><br>
      Latitude, Longitude:       
      <input id='textBox' type="text" style="width:250px;"/>
   </body>
</html>
Show:
© 2014 Microsoft