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

1

9

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.

Tollgate answered 6/4, 2011 at 12:31 Comment(1)
Does anybody else has ever faced similar issue.. or I am the only one out here facing this issue??Tollgate
H
10

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.

Horsehair answered 13/4, 2011 at 16:13 Comment(2)
This worked for me when I increased the interval; I used 1000 instead of 10.Jacquelynejacquelynn
What's the need for the if(eval("typeof VEMap") != "undefined") ? Wouldn't if(window.VEMap) work too?Seesaw

© 2022 - 2024 — McMap. All rights reserved.