javascript - getSVGDocument 反复抛出 "0x80020003 - JavaScript runtime error: Member not found"

标签 javascript svg

英国国家统计局提供英国 2011 年全国人口普查数据。他们提供的一种访问方法是通过 SOAP API,他们在页面 NeSS Data Exchange V2.0 上给出了如何使用其 API 的示例。 。我无法让一个示例正常工作。位于NDE v2.0 Excel Client下在邮政编码 NDE Hub Client REST v2.0 (Zip) 37 Mb ,一个“基于 Excel 的集线器演示应用程序,允许用户建立已保存数据的存储库,并通过 SVG 专题图查看它”。

map <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()">

调用 initialise在“包括/Startup.js”中。 initialise是抛出异常的地方。当代码到达

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

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

问题How to check if an embedded SVG document is loaded in an html page?可能相关。我无法使用Erik Dahlström's answer因为我已经依赖 onload正如他建议的那样。我已经尝试过Mocky's answer因此

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

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

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

关于javascript - getSVGDocument 反复抛出 "0x80020003 - JavaScript runtime error: Member not found",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16559121/

相关文章:

python - 如何使用 Python 缩放 SVG 文件中的路径元素

javascript - 如何在没有外部库的情况下从 Javascript 书签复制到剪贴板?

javascript - 如何在单个 View /页面中呈现两个电子签名组件?

javascript - 为什么变换会移动整个坐标系而不是仅仅移动 SVG 中的元素?

d3.js - 如何计算成对的贝塞尔 S 曲线,使它们之间的空间具有恒定的厚度?

javascript - 旋转标签 nvd3 折线图

javascript - 为什么我可以插入可读流?

javascript - 我从头开始创建 html 解析器的想法可行吗?

javascript - 自定义解构模式

javascript - 保存 SVG,背景图像被遗漏