VE Maps v6 抛出仅限 IE8 的 JS 错误,“抛出异常且未捕获”

发布于 2024-11-01 20:31:37 字数 4243 浏览 0 评论 0原文

来自MSDN论坛,即使从 Virtual Earth Dev SDK 复制并粘贴最简单的示例,也会导致仅在 IE8 中抛出相同的异常。但是,使用 http://ecn.dev.virtualearth.net 的同一示例/mapcontrol/mapcontrol.ashx?v=6.3 (代替 ?v=6,即使 ?v=6 据称被转发到?v=6.3) 修复了错误。


注意:此处显示的代码已更新,以反映我在遵循建议后的最新尝试 - 此代码仅在 IE8 中仍然出错!

我有一个使用 http://ecn.dev.virtualearth.net/ 的页面mapcontrol/mapcontrol.ashx?v=6 显示地图。仅在 IE8 中存在 JS 错误,并且地图无法工作。该地图在所有其他浏览器中都能完美运行。

抛出异常但未捕获 mapcontrol.ashx?v=6&_=1303145735376, 第 149 行字符 618137 throw new VEException("VEMap:cstr","err_invalidelement",L_invalidelement_text);

症状:

  • 虚拟地球库加载正常。
  • loadMap 没有任何语法错误。
  • 在调用 loadmap() 之前、期间和之后,地图的 div 占位符存在于页面上。
  • 该错误仅在调用 loadmap() 时抛出;不是在库加载时。
  • 该地图在除 IE8 之外的所有浏览器中都显示良好。
  • 所有 IE8 的用户每次都会遇到这个错误(据我所知,我所有的测试人员都使用过 XP,但其中一个可能使用的是 Vista)。
  • 在 IE8 中,会弹出有关错误的通知,我可以在脚本调试器(上面)中获取更多信息。然后IE8中就不会出现地图了。

最初所有的 JS 都是通过 script 标签链接的。然后错误仍然发生。由于各种原因,我现在改用 yepnope 了。 yepnope 加载的最后一个 JS 文件是与地图相关的文件,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);

基本上,只需调用 loadmap(),它就存在,这是一个与我们的后端代码配合编写的函数。后端代码将其作为嵌入脚本输出到 HTML 中。 loadmap() 看起来像:

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;             
}

对 loadmap() 的所有更改仅在我的本地开发计算机上进行和测试。到目前为止,对 loadmap() 的调整没有任何帮助——这并不奇怪,因为在其他页面上使用相同的函数没有任何问题。

至于修复它,我尝试过:

  • 更改 X-UA-Compatible (基于我发现的线程)。

最初我使用的是:

<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />

我尝试将其更改为以下内容,因为有几个线程提到解决了该问题。

<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7" />
<meta http-equiv="X-UA-Compatible" content="IE=7" />

我还尝试完全删除 X-UA-Compatible。这些都没有解决问题,我在 IE8 中仍然遇到错误。手动切换兼容模式也没有效果。

  • 更改了 loadmap() 的语法。 (最后一次迭代见上文)

    1. 根据论坛上的建议,移动了 pin 代码,以便在 propertyLayer.AddShape(propertyPin) 之前完成 map.AddShapeLayer(propertyLayer)。 IE8 仍然错误。
    2. 将所有全局声明的变量移至 loadmap() 函数内。 IE8 仍然错误。
    3. 确保在 SetClientToken 之后(以及 HideDashboard 和其他所有内容之前)立即调用 VEMap.LoadMap() 方法。 IE8 仍然错误。

示例链接--redacted--。请注意,示例链接不会显示我尝试的修复,因为它是实时的。但由于尝试的修复尚未解决该问题,因此请忽略该问题并参阅这篇文章以获取仍然无法正常工作的最新代码。

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:

  • The virtual earth library gets loaded just fine.
  • loadMap doesn't have any syntax errors.
  • The div placeholder for the map exists on the page before, during, and after loadmap() is called.
  • The error gets thrown only around the time loadmap() is called; not when the library loads.
  • The map shows up just fine in all browsers but IE8.
  • All users of IE8 get the error every time (so far as I know all my testers have been on XP, but one may be on Vista).
  • In IE8 a notification pops up about the error, I can get some more info in the script debugger (above). Then no map appears in IE8.

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:

  • Changing X-UA-Compatible (based on threads I found).

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)

    1. Moved pin code so that map.AddShapeLayer(propertyLayer) was done before propertyLayer.AddShape(propertyPin) based on a suggestion on a forum. IE8 still errors.
    2. Moved all the globally declared variables inside the loadmap() function. IE8 still errors.
    3. Ensured VEMap.LoadMap() method was called immediately after SetClientToken (and before HideDashboard & everything else). IE8 still errors.

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

尴尬癌患者 2024-11-08 20:31:37

要尝试两件事:

首先,只能在调用 LoadMap() 方法之后调用 HideDashboard() 方法(通常,VEMap 对象上的所有方法)。不过,SetClientToken() 之前没问题。

其次,您在 var a = new Array(); 行中声明了一个名为 a 的全局变量。
根据记忆,过去曾出现过与 Bing Maps API 中声明的变量名称冲突的问题,而且我知道混淆的 Bing Maps 库确实使用单字符函数和参数名称:a、b、c、d 等。如果这确实必须是一个全局变量,那么尝试将其命名为更具描述性的名称,以避免覆盖现有变量的可能性。

Two things to try:

Firstly, the HideDashboard() method (as, in general, all methods on the VEMap object) should only be called after the LoadMap() method has been called. SetClientToken() is ok before though.

Secondly, you're declaring a global variable called a, in the line var a = new Array();
From memory, there have been problems in the past with name conflicts with variables declared in the Bing Maps API, and I know that the obfuscated Bing Maps library certainly does use single character function and parameter names: a,b,c,d etc. If this really must be a global variable, then try naming it to something else more descriptive to avoid the possibility that you're overwriting an existing variable.

菊凝晚露 2024-11-08 20:31:37

来自MSDN论坛将脚本调用更改为 ?v=6.3(代替 ?v=6)可修复该错误。

尽管 ?v=6 据称被转发到 ?v=6.3 并且这两个脚本据说是相同的!)

升级到 v7 也可以工作,尽管语法发生了变化loadmap() 函数需要升级。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文