Share via


VEBirdseyeScene.LatLongToPixel Method

You are not viewing the latest version of the AJAX control. Bing Maps AJAX V7 is the recommended JavaScript control for Bing Maps. If you need this documentation, it is available in as a CHM or PDF download.

Converts a VELatLong Class object (latitude/longitude pair) to the corresponding pixel on the map.

VEBirdseyeScene.LatLongToPixel(LatLong, zoomLevel);

Parameters

Parameter Description

LatLong

A VELatLong Class object, which contains the latitude and longitude of a point. This method also accepts an encrypted VELatLong object, as supplied by the VEBirdseyeScene.PixelToLatLong Method.

zoomLevel

The zoom level of the current map view

Return Value

A pixel location of the VELatLong Class point. This object has two properties, x and y.

Remarks

The x- and y-coordinates of the pixel returned by this method are with respect to the top-left corner of the bird's eye scene. This differs from VEMap.LatLongToPixel Method, which returns x- and y-coordinates with respect to the top-left corner of the map view.

Note

VEMap.LatLongToPixel can also be called in bird's eye view.

Example

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://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="https://ecn.dev.virtualearth.net/mapcontrol/mapcontrol.ashx?v=6.3"></script>

      <script type="text/javascript">
         var map = null;
         var be = null;
         var pixel = null;
         var encLatLong = null;
      
         function GetMap()
         {
            map = new VEMap('myMap');
            map.LoadMap(new VELatLong(47.7,-122.2),14);

            map.SetZoomLevel(15);
            SetPin();
         }
      
         function SetPin()
         {
            if (map.IsBirdseyeAvailable())
            {
               be = map.GetBirdseyeScene();
               pixel = be.LatLongToPixel(map.GetCenter(), map.GetZoomLevel());
               encLatLong = be.PixelToLatLong(pixel, map.GetZoomLevel());
               AddPin(encLatLong);
            }
            else
            {
               alert("Bird's eye images are not available at this location and zoom level.");
               map.AddPushpin(map.GetCenter());
            }
         }
      
         function AddPin(encLatLong)
         {
            map.DeleteAllPushpins();

            var pin = new VEPushpin(
               'mypin', 
               encLatLong,
               null,
               'Encrypted Location',
               'Pushpin added to encrypted LatLong point.',
               null,
               null,
               null);

            map.AddPushpin(pin);
         }
      
         function FindValid()
         {
            var msgTxt = "";

            be = map.GetBirdseyeScene();

            if (be != null)
            {
               pixel = be.LatLongToPixel(map.GetCenter(), map.GetZoomLevel());
               encLatLong = be.PixelToLatLong(pixel, map.GetZoomLevel());

               if (be.ContainsPixel(encLatLong.x, encLatLong.y, map.GetZoomLevel))
               {
                  msgTxt = "ContainsPixel has returned true";
               }
               else
               {
                  msgTxt = "ContainsPixel has returned false";
               }
            }
            else
            {
               msgTxt = "Bird's eye images are not available at this location and zoom level.";
            }

            alert(msgTxt);
         }
      </script>
   </head>
   <body onload="GetMap();">
      <div id='myMap' style="position:relative; width:400px; height:400px;"></div>
      <input id="setpin" type="button" value="Add Pushpin" name="setpin" 
         onclick="SetPin();"><br />
     <input id="findvalid" type="button" value="Is Tile Valid?" name="setpin" 
         onclick="FindValid();">
   </body>
</html>