Export (0) Print
Expand All

PixelReference Enumeration

Bing

Contains constants used to show how pixels are defined.

Constants

Name Description

control

The pixel is defined relative to the map control’s root element, where the top left corner of the map control is (0, 0). Using this option might cause a page reflow which may negatively impact performance.

page

The pixel is defined relative to the page, where the top left corner of the HTML page is (0, 0). This option is best used when working with mouse or touch events. Using this option might cause a page reflow which may negatively impact performance.

viewport

The pixel is defined in viewport coordinates, relative to the center of the map, where the center of the map is (0, 0). This option is best used for positioning geo-aligned entities added to the user layer.

Methods

Name Definition Return Value Description

isValid

isValid(reference: PixelReference )

boolean

Determines whether the specified reference is a supported PixelReference.

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.pageX, e.pageY, Microsoft.Maps.PixelReference.page);
                  var loc = e.target.tryPixelToLocation(point, Microsoft.Maps.PixelReference.page);

                  if (loc!=null)
                  {
                     alert("The location " + loc.latitude + ", " + loc.longitude + " was clicked.");
                  }
 
              }
          }



      </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>
   </body>
</html>
Show:
© 2014 Microsoft