code_junkie

How do I find the the exact lat/lng coordinates of a birdseye scene in Virtual Earth?

Nov 10th, 2011
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.92 KB | None | 0 0
  1. function GetCenterLatLong()
  2. {
  3. //Check if in Birdseye or Oblique Map Style
  4. if (map.GetMapStyle() == VEMapStyle.Birdseye || map.GetMapStyle() == VEMapStyle.BirdseyeHybrid)
  5. {
  6. //IN Birdseye or Oblique Map Style
  7.  
  8.  
  9. //Get the BirdseyeScene being displayed
  10. var birdseyeScene = map.GetBirdseyeScene();
  11.  
  12.  
  13. //Get approximate center coordinate of the map
  14. var x = birdseyeScene.GetWidth() / 2;
  15. var y = birdseyeScene.GetHeight() / 2;
  16.  
  17. // Get the Lat/Long
  18. var center = birdseyeScene.PixelToLatLong(new VEPixel(x,y), map.GetZoomLevel());
  19.  
  20. // Convert the BirdseyeScene LatLong to a normal LatLong we can use
  21. return (new _xy1).Decode(center);
  22. }
  23. else
  24. {
  25. // NOT in Birdseye or Oblique Map Style
  26. return map.GetCenter();
  27. }
  28. }
  29.  
  30. function getBirdseyeViewLatLong(vePixel)
  31. {
  32. var be = map.GetBirdseyeScene();
  33.  
  34. var centrePixel = be.LatLongToPixel(map.GetCenter(), map.GetZoomLevel());
  35.  
  36. var currentPixelWidth = be.GetWidth();
  37. var currentPixelHeight = be.GetHeight();
  38.  
  39. var mapDiv = document.getElementById("map");
  40. var mapDivPixelWidth = mapDiv.offsetWidth;
  41. var mapDivPixelHeight = mapDiv.offsetHeight;
  42.  
  43. var xScreenPixel = centrePixel.x - (mapDivPixelWidth / 2) + vePixel.x;
  44. var yScreenPixel = centrePixel.y - (mapDivPixelHeight / 2) + vePixel.y;
  45.  
  46. var position = be.PixelToLatLong(new VEPixel(xScreenPixel, yScreenPixel), map.GetZoomLevel())
  47. return (new _xy1).Decode(position);
  48. }
  49.  
  50. var northWestLL = (new _xy1).Decode(map.GetMapView().TopLeftLatLong);
  51. var southEastLL = (new _xy1).Decode(map.GetMapView().BottomRightLatLong);
  52.  
  53. function GetInfo()
  54. {
  55. alert('The latitude,longitude at the center of the map is: '+map.GetCenter());
  56. }
Add Comment
Please, Sign In to add comment