getSVGDocument反复抛出“0x80020003 - JavaScript运行时错误:未找到成员”

getSVGDocument repeatedly throwing "0x80020003 - JavaScript runtime error: Member not found"

本文关键字:运行时错误 成员 JavaScript 0x80020003 getSVGDocument      更新时间:2023-09-26

英国国家统计局提供了英国2011年全国人口普查的数据。他们提供的一种访问方法是通过SOAP API,他们在页面NeSS Data Exchange V2.0上给出了如何使用他们的API的示例。我有一个例子不能正常工作。NDE Hub Client REST v2.0 (ZIP) 37mb,一个"基于Excel的Hub演示应用程序,允许用户建立保存数据的存储库,并通过SVG专题地图查看它"。

地图<DIV> SVG数据通过以下几行添加到页面中(在'Sources/ThematicMap.htm'中)

document.writeln('<DIV id=mapPanel style="position:absolute;left:26%;top:7%; height=63%; width=50%;">')
document.writeln('<EMBED height=100% width=100% name=svgMap src="../Boundaries/' + svgFile + '" type=image/svg-xml>')
document.writeln('</DIV>');
(注意:

他们原来的代码是..''Boundaries'',我改成了../Boundaries/。两者都会导致相同的错误)

在中间行上放置一个断点表明svgFile变量被设置为"la_12UB.svg",并且该文件存在于"Boundaries"目录中。'Boundaries/la_12UB.svg'是这样开始的。

<?xml version="1.0" encoding="iso-8859-1"?>
<?xml-stylesheet type="text/css" href="external.css" ?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 20000303 Stylable//EN" "http://www.w3.org/TR/2000/03/WD-SVG-20000303/DTD/svg-20000303-stylable.dtd">
<svg xml:space="preserve"  preserveAspectRatio="xMinYMin meet" id="MainSVG" width="395" height="420" viewBox="0 0 900 650"> 
  <g class="mapEdge" opacity="0.2">
      <rect x="0" y="0" width="100%" height="100%"/>            
  </g>
  <svg xml:space="preserve" preserveAspectRatio="xMinYMin meet" id="Map" onload="init(evt)" width="100%" height="100%" viewBox="541512 -262080 7829 10000">
      <g class="mapBackground" transform="translate(1000,500) scale(1, -1)">
          <path id="00JA" d="M 533246,308907 534698,301468 539690,302984 540167,303513 539729,302866 534716,301443 527492,299370 527194,299301 522976,298284 523340,298070 522788,297938 522896,297322 522287,296297 522752,296256 523134,295665 522992,295319 522142,295666 521979,295371 521209,295267 520981,294831 520598,295324 519801,295441 519692,294834 520037,294424 519608,293815 519307,293871 519182,293126 517207,292629 517375,292088 516523,291182 516301,291471 515933,291255 515710,292076 514043,294384 513155,295603 513611,295848 513756,296170 513511,296320 512826,296386 512500,296931 512035,297564 510765,297353 510349,297748 509529,297818 509347,298690 508718,299559 507903,299503 507472,299058 506810,299452 503855,298555 503186,298398 503176,298820 502294,299230 501879,299841 502341,300260 502671,301563 502968,301637 503035,302936 503435,302942 503614,303338 503418,304478 502550,305148 502370,304967 501950,305791 502644,306453 503260,306347 503212,306752 503764,306896 504753,306844 504914,307391 507122,306620 507966,306784 508919,307439 510829,308187 511058,308184 512364,308996 512669,309872 514367,309757 516476,308975 517551,307531 517895,307411 520168,309004 520976,309160 521409,309326 522343,307609 523190,308534 525850,307595 525946,307970 528419,309965 529405,309387 530284,310000 530904,310008 531006,310370 531399,310254 532300,309733 533178,309331 533246,308907 z"/>

。它看起来是正确的格式,并充满了SVG数据。

'Sources/ThematicMap.htm'也包含

<BODY onload="initialise()">

在'Includes/Startup.js'中调用initialiseinitialise是抛出异常的地方。当代码到达

行时
svgMapDoc = document.svgMap.getSVGDocument();

引发错误0x80020003 - JavaScript runtime error: Member not found。设置一个断点,我可以看到document.svgMap不是null也不是undefined,尽管它似乎充满了默认值,而不是我期望的路径数据的财富(但我不确定在哪里寻找)。

问题如何检查嵌入式SVG文档是否加载在html页面中?可能是相关的。我不能使用Erik Dahlström的答案,因为我已经像他建议的那样依赖onload。我已经试过了Mocky的答案

function checkSVGMapReady() {
    try {
        svgMapDoc = document.svgMap.getSVGDocument();
    } catch (e) { }
    if (svgMapDoc === undefined) {
        setTimeout("checkSVGMapReady()", 300);
    } else {
        svgMapReady();
    }
}

但是每次通过迭代调用都会捕获相同的错误。

(注意:

我认为这些例子是在IE6, IE7, Firefox 2上测试的,至少他们的另一个例子的自述文件是这样说的,而我使用的是IE10。我也尝试过Chrome和Firefox,虽然我没有看到相同的错误信息,但我也没有看到SVG数据呈现。

有没有人知道为什么调用getSVGDocument会抛出0x80020003 - JavaScript runtime error: Member not found以及如何修复它?

这里似乎有很多问题。

type=image/svg-xml无效。你必须使用type=image/svg+xml .

那么我认为你应该试着这样做…

  if (document.svgMap && document.svgMap.contentDocument)
    svgMapDoc = document.svgMap.contentDocument;
  else try {
    svgMapDoc = document.svgMap.getSVGDocument();
  }
  catch(exception) {
    alert('Neither the HTMLObjectElement nor the GetSVGDocument interface are implemented');
  }

最后,初始化svgMapDoc的代码是从主体的onload事件中调用的,但应该是嵌入的onload触发它,看起来像这样…

document.writeln('<EMBED height=100% width=100% onload="initialise()" name=svgMap src="../Boundaries/' + svgFile + '" type=image/svg+xml>')