我有一个<object>
加载外部 svg 文件的位置:
<object type="image/svg+xml" data="system.svg" id="Graph_Container" class="GraphContainmentArea">
Your browser does not support SVG
</object>
我正在使用以下库的 SVG 平移和缩放功能:https ://github.com/ariutta/svg-pan-zoom 。但是,仅将svg-pan-zoom.js
文件添加到我的页面似乎不足以向object
代码中包含的 svg 添加任何类型的功能:
<?xml version="1.0" encoding="UTF-8"?>
<iw:iwidget id="GraphContainer" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:iw="http://www.ibm.com/xmlns/prod/iWidget" supportedModes="view edit"
lang="en" iScope="GraphContainerScope" title="Graph Container Widget">
<iw:content mode="view">
<![CDATA[
<link rel="stylesheet" href="/Widgets/GraphContainerWidget/css/graphcontainer.css" />
<script src="/Widgets/GraphContainerWidget/js/jquery.min.js"></script>
<div id="GraphContainer_IWID_" class="search-area" style="display:block;">
<div class="content-area" id="content-area_IWID_">
<div class="RightPanel" id="rightPanel_IWID_">
<table id='main-content_IWID_' class="links-included">
<tr>
<object type="image/svg+xml" data="" id="_IWID_Graph_Container" class="GraphContainmentArea">
Your browser does not support SVG
</object>
</tr>
<tr><td></td></tr>
<tr><td></td></tr>
<tr>
<td id="_IWID_Graph_Footer" class="FooterContainmentArea">Optional Footer</td>
</tr>
</table>
<div id='footer_IWID_' class="footer">
</div>
</div>
</div>
</div>
<script src="/Widgets/GraphContainerWidget/js/svg-pan-zoom.js"></script>
<script type="text/javascript">
var _IWID_attributesItemSet = iContext.getiWidgetAttributes();
var _IWID_iDescriptor = iContext.getiDescriptor();
var SVG_GRAPH_URL = _IWID_attributesItemSet.getItemValue("wid_import_field");
var SVG_FOOTER = _IWID_attributesItemSet.getItemValue("wid_footer_field");
var SVG_MULTI = _IWID_attributesItemSet.getItemValue("wid_multigraphs_field");
console.log("Viewmode SRC URL: " + SVG_GRAPH_URL);
try {
if (SVG_GRAPH_URL !== null && SVG_GRAPH_URL !== "") {
var finished_URL = httpcheck() + SVG_GRAPH_URL;
$("#Graph_Container").attr("data", finished_URL);
setTimeout(function() {
svgPanZoom("#_IWID_Graph_Container", {
zoomEnabled: true,
controlIconsEnabled: true
});
}, 2000);
} else {
alert("No URL passed to graph container!")
}
}
catch(e) {
console.log(e.name + "-" + e.description + "-" + e.message);
}
function httpcheck() {
if (SVG_GRAPH_URL.substring(0,7) == "http://" || SVG_GRAPH_URL.substring(0,8) == "https://") {
return "";
} else {
return "http://";
}
}
</script>
]]>
</iw:content>
注意:除了 SVG-Pan-Zoom.js 之外,jQuery 是我唯一使用的库 关于如何解决此问题/改进代码的任何提示?
我得到的当前错误是svgPan is not defined
.
上面的代码更新了