Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Issue with Bing Map --p_elSource.attachEvent is not a function

I am facing major problem with Bing Maps. I am using : http://dev.virtualearth.net/mapcontrol/mapcontrol.ashx?v=6.3

First I am getting error in firebug as :

 this.CreditsFor=function(a,i,j,h)
 {
  var e=[];
  if(a!="undefined"&&a!=null&&typeof m_tableKeys[a]!="undefined"&&
   ........
   MVC_Init_FlatlandView_Drawing();
   MVC_Init_View3D_Drawing()};
   if(typeof closeDependency!="undefined")
       closeDependency("mapcontrol.js")

After that I put the .LoadMap() call inside try-catch block. it was throwing exception:

p_elSource.attachEvent is not a function

I already tried out following solutions whihc were recommended in msdn forums:

  • Setting defualt value for VEMapOptions.BirdseyeOrientation before calling LoadMap()
  • Ensured that DOCTYPE is there

This happens only when firebug is enabled.

like image 304
ZeNo Avatar asked Apr 06 '11 12:04

ZeNo


People also ask

How many destinations can you add to Bing Maps?

Bing Maps allows you to add multiple destinations/stops to the route up to 25 stops. Plan a route and choose from options like walking, biking, public transport mode, or driving directions. You can also choose to print the routes you plan. Save the routes and destinations.

How do I update Bing Maps?

Update your Bing Maps Dev Center informationSign in to the Bing Maps Dev Center. Click Update or view account details to view your account details, and then click Edit. Make your changes to the account information, and then click Save.

How do I embed a Bing map into my website?

Option 1: Go to https://www.bing.com/maps, create the map you want, and then click Share. If you want control over basic parameters like size and imagery, click Customize and preview. This option will provide you with HTML that you can embed into your web page.


1 Answers

Zeno,

Are you using FF4? I had the problem in FF4, and it was caused by a race condition where my script was calling VE functions that hadn't been defined yet. I got a solution here.

In particular, note the answer from Josh Unger where he describes using setInterval to wait for an auxiliary library to load and do it's thing.

var interval = setInterval(function() {
    if (eval("typeof VEMap") != "undefined" &&
        document.getElementById("map").attachEvent != undefined)   
    {
        clearInterval(interval);
        LoadMap();
    }
}, 10);

You'll have to update the sample code to fit your circumstances. The important part is to avoid calling anything in VE until you are sure that the VE script has loaded and the auxiliary library has loaded.

People using FF4 reported the problem to me recently. I suspect that something about FF4 compared to FF3 (perhaps faster script execution, or a difference in when scripts execute) has triggered the error. In any case, when I updated my code to delay calling VE until the libs were loaded, the error went away and the maps worked properly.

Note that I am not doing lazy loading, and Firebug is not the issue. Those were evidently factors when the thread was active in 2008/2009.

like image 174
Johnny Cee Avatar answered Sep 25 '22 19:09

Johnny Cee