In my BODY ONLOAD I call a function that loads a map. I want to determine if a Birdseye map is available for the location loaded; however, it never works (I know this because I have tested it against locations that have Birdseye maps).
Here is my code (GetMap() is called from BODY ONLOAD):
var map = null;
function GetMap()
{
map = new VEMap('myMap');
map.LoadMap(new VELatLong(33.85, -84.363192), 10 ,'h' , false);
if (map.IsBirdseyeAvailable())
{
map.SetMapStyle(VEMapStyle.Birdseye);
}
else
{
alert("Birdseye not available.");
}
}
I suspect that the problem is that the map has not fully loaded by the time IsBirdseyeAvailable() has been called. If I add a button to the page and call IsBirdseyeAvailable() from the onclick() event of the button, it works -- but this isn't what I really want to do. I want to immediately know if birdseye is available and load it immediately after the map loads WITHOUT user interaction.

IsBirdseyeAvailable() does not work
Ambrish Mishra - MSFT
Your correct that this code doesn't work. That's because VE is asynchronous. That means that everything runs together (as compared to synchronous --> finishing one job before another), and you don't have as much control of the actual execution order of the program. Applying that to the code, you can't expect the map.loadMap to fire right before map.IsBirdsEyeAvailable. The solution Kartik provides should be the right idea, have an event handler to deal with whenever the map has changed view.
alungwyther
Try attaching a function to the onChangeView event:
//the following function occurs onload.
function GetMap()
{
map = new VEMap('myMap');
map.LoadMap();
map.AttachEvent('onchangeview', onChangeView);
}
// the following occurs when the onchangeview event fires.
function onChangeView(e)
{
if (map.IsBirdseyeAvailable())
{
alert("Bird's Eye images are available!!!");
}
}
I find this pops up an alert straight away if it is available.
AudiRS6
Using a timeout isn't the best idea. If the user has a slow internet connection your timeout maybe fails.
A better solution is using the "onobliqueenter" event of the VEMap object. If you want to switch to Birdseye (if available) only the first time the map loads, you can implement it like that:
var map = null;
var enable_be = true;
function enable_birdseye()
{
if (map.IsBirdseyeAvailable() && enable_be)
{
map.SetMapStyle('o');
enable_be = false;
}
}
function disable_be()
{
enable_be = false;
}
function GetMap()
{
map = new VEMap('myMap');
map.LoadMap(new VELatLong(48.131892288594599, 11.5708373502637), 16, 'r');
map.AttachEvent("onobliqueenter", enable_birdseye);
map.AttachEvent("onchangeview", disable_be);
}
Handling the "onviewchange" event prevents you from switching to birdseye every time birdseye is avaialbe while the user is working with the map.
Stephan
vb2005
>8-)
Hank
k.praful
Hi,
I have two comments to make.
I've tested the V5 Earth Map Control SDK and Internet Explorer 6 SP1 and Internet Explorer 7.
1. Try attaching the "onChangeView" event handler before calling LoadMap().
Otherwise you won't catch the 'onchangeview' event when the map loads.
2. Even attaching the event handler before LoadMap didn't work properly for me. When the page loads, the map.IsBirdseyeAvailable() function returns an incorrect result.
For this reason I've used a timeout.
<
html><head>
<title>Testing bird's eye view in V5 </title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<script src='http://dev.virtualearth.net/mapcontrol/mapcontrol.ashx v=5'></script>
<script>
var map = null;
var latitude=33.8;
var longitude= -84.363192;
var zoomLevel=10;
var loadMapFirstTime=true;
function GetMap()
{
}
function onChangeViewHandler()
{
}
function EnableDisableBirdsEye()
{
}
</script>
</head>
<body onload="GetMap();">
<div id='myMap' style="position:relative; width:400px; height:400px; z-index: 100; left: 40px; top: 8px;"></div>
</body>
</html>