From the MSDN forums, even copying and pasting the simplest example from the Virtual Earth Dev SDK results in the same exception being thrown in IE8 only. However, the same example using http://ecn.dev.virtualearth.net/mapcontrol/mapcontrol.ashx?v=6.3 (in place of ?v=6, even though ?v=6 is allegedly forwarded to ?v=6.3) fixes the error.
Note: code shown here is updated to reflect my most recent attempts after following recommendations made--this code is STILL erroring in IE8 only!
I have a page using http://ecn.dev.virtualearth.net/mapcontrol/mapcontrol.ashx?v=6 to show maps. In IE8 only there is a JS error and the map doesn't work. The map works beautifully in all other browsers.
Exception thrown and not caught mapcontrol.ashx?v=6&_=1303145735376, line 149 character 618137 throw new VEException("VEMap:cstr","err_invalidelement",L_invalidelement_text);
Symptoms:
Originally all the JS was linked with script tags. The error still occurred then. I've now switched to yepnope for various reasons. The last JS file yepnope loads is one related to the maps, jquery.vemap.js:
(function($){
$.fn.showMap = function(){
var jqoThis = this;
jqoThis.oneTime(1000, "loadVELibrary", function(){
$.getScript("http://ecn.dev.virtualearth.net/mapcontrol/mapcontrol.ashx?v=6", function(){
jqoThis.oneTime(1000, "loadMap", function(){
if(typeof(loadmap) == 'function'){ var map = loadmap(); }
$(this).oneTime(500, "setZoom", function(){
if(typeof(map) == 'object'){ if(typeof(map.SetZoomLevel) == 'function'){ map.SetZoomLevel(13); } }
}); // oneTime "setZoom"
}); // oneTime "loadMap"
}); // $.getScript
}); // oneTime "loadVELibrary"
}; // showMap
})(jQuery);
Basically this exists pretty much just call loadmap(), which is a function written in cooperation with our backend code. The backend code outputs it in the HTML as an embedded script. loadmap() looks like:
function loadmap()
{
var map = new VEMap('cmMap'),
arp = [],
propertyLayer = null,
propertypoint = null,
propertyPin = null,
customicon = null,
token = '...',
label = "...";
map.SetClientToken(token);
map.LoadMap();
map.HideDashboard();
propertyLayer = new VEShapeLayer();
map.AddShapeLayer(propertyLayer);
propertypoint = new VELatLong(parseFloat(33.12966),parseFloat(-117.333488));
arp[0] = propertypoint;
propertyPin = new VEShape(VEShapeType.Pushpin,propertypoint);
customicon = new VECustomIconSpecification();
customicon.Image = "....";
propertyPin.SetCustomIcon(customicon);
propertyPin.SetDescription(label);
propertyLayer.AddShape(propertyPin);
map.SetCenterAndZoom(propertypoint,13);
return map;
}
All changes to loadmap() are only made and tested on my local dev machine. So far no adjustments to loadmap() have helped -- which isn't exactly surprising, since the same function is used on other pages with no issues.
As far as fixing it, I have tried:
Originally I was using:
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
I tried changing it to the below since a few threads mentioned that fixed the issue.
<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7" />
<meta http-equiv="X-UA-Compatible" content="IE=7" />
I also tried taking X-UA-Compatible out entirely. None of this fixed the issue, I continued to get the error in IE8. Manually toggling compatibility mode also had no effect.
Changed the syntax of loadmap(). (See above for last iteration)
Example link --redacted--. Please note the example link will not show the fixes I attempt, because it's live. But since the attempted fixes have not fixed the issue, please ignore that and refer to this post for the up-to-date code that still doesn't work.
From the MSDN forums, changing the script call to ?v=6.3 (in place of ?v=6) fixes the error.
(Even though ?v=6 is allegedly forwarded to ?v=6.3 and the two scripts are supposedly identical!)
Upgrading to v7 also works, although changes to the syntax of the loadmap() function are necessary to upgrade.