-- 作者:342989854
-- 发布时间:6/12/2010 3:55:00 PM
--
我把代码展示如下: <?xml version="1.0" encoding="utf-8" standalone="no"?> <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11-flat-20030114.dtd"> <svg width="100%" height="100%" xmlns:svg="http://www.w3.org/2000/svg" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" preserveAspectRatio="xMidYMid meet" zoomAndPan="magnify" onload="Init(evt)" onmousedown="Grab(evt)" onmousemove="Drag(evt)" onmouseup="Drop(evt)"> <defs> <menu id='Menu' > <header>Menu utilisateur</header> <item id='Menu0' onactivate="insert(evt)">添加节点</item> <item id='Menu1' onactivate='cd1()'>菜单1</item> <item id='Menu2' onactivate='cd2()'>菜单2</item> <item id='none1'/> <item id='Menu3' action="ZoomOut">缩小</item> <item id='Menu4' action="ZoomIn">放大</item> <item id='none2'/> <item id='Menu5' action='ViewSource'>浏览源代码</item> </menu> </defs> <title>Drag And Drop</title> <script type="text/ecmascript" xlink:href="../chuangkou/helper_functions.js"/> <script type="text/ecmascript" xlink:href="../chuangkou/mapApp.js"/> <script type="text/ecmascript" xlink:href="../chuangkou/timer.js"/> <script type="text/ecmascript" xlink:href="../chuangkou/Window.js"/> <script type="text/ecmascript" xlink:href="../chuangkou/textbox.js"/> <script type="text/ecmascript" xlink:href="../chuangkou/button.js"/> <script type="text/javascript"><![CDATA[ var c=1; var prr;//初始化菜单 var SVGDocument = null; var SVGRoot = null; var TrueCoords = null; var GrabPoint = null; var BackDrop = null; var DragTarget = null; function Init(evt){ SVGDocument = evt.target.ownerDocument; SVGRoot = SVGDocument.documentElement; TrueCoords = SVGRoot.createSVGPoint(); GrabPoint = SVGRoot.createSVGPoint(); BackDrop = SVGDocument.getElementById("BackDrop");//拖动 root=SVGDocument.rootElement;//添加 var newMenuRoot=parseXML(printNode(SVGDocument.getElementById('Menu')),contextMenu); contextMenu.replaceChild(newMenuRoot,contextMenu.firstChild); prr=SVGDocument.getElementById("rr"); } function Grab(evt){ var targetElement = evt.target; if (BackDrop != targetElement){ DragTarget = targetElement; DragTarget.parentNode.appendChild(DragTarget); DragTarget.setAttributeNS(null, "pointer-events", "none"); var transMatrix = DragTarget.getCTM(); GrabPoint.x = TrueCoords.x - Number(transMatrix.e); GrabPoint.y = TrueCoords.y - Number(transMatrix.f); } }; function Drag(evt){ GetTrueCoords(evt); if (DragTarget){ var newX = TrueCoords.x - GrabPoint.x; var newY = TrueCoords.y - GrabPoint.y; DragTarget.setAttributeNS(null, "transform", "translate(" + newX + "," + newY + ")"); } }; function Drop(evt){ if (DragTarget){ var targetElement = evt.target; DragTarget.setAttributeNS(null, "pointer-events", "all"); if ("Folder" == targetElement.parentNode.id){ targetElement.parentNode.appendChild( DragTarget ); } else{} DragTarget = null; } }; function GetTrueCoords(evt){ var newScale = SVGRoot.currentScale; var translation = SVGRoot.currentTranslate; TrueCoords.x = (evt.clientX - translation.x)/newScale; TrueCoords.y = (evt.clientY - translation.y)/newScale; }; function insert(evt) { obj=evt.target; } ]]></script> <rect id="BackDrop" x="-10%" y="-10%" width="110%" height="110%" fill="none" pointer-events="all" /> <g id="Folder"> <rect id="FolderRectangle" x="200" y="100" width="50" height="50" style="fill:blue; stroke:brown; stroke-width:3;"/> </g> </svg> 上面一段是svg文件,首先自定义了右键菜单,而且增加了移动功能,我的目的是在右键菜单的添加节点中触发insert()事件,添加下面我定义的对话框 对话框如下: <?xml version="1.0" standalone="no"?> <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"> <?AdobeSVGViewer save="snapshot"?> <svg width="100%" height="100%" viewBox="0 0 1024 700" onload="init(evt)" xmlns:batik="http://xml.apache.org/batik/ext" xmlns:attrib="http://www.carto.net/attrib" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns="http://www.w3.org/2000/svg" preserveAspectRatio="xMidYMid meet" zoomAndPan="magnify"> <script type="text/ecmascript" xlink:href="../chuangkou/helper_functions.js"/> <script type="text/ecmascript" xlink:href="../chuangkou/mapApp.js"/> <script type="text/ecmascript" xlink:href="../chuangkou/timer.js"/> <script type="text/ecmascript" xlink:href="../chuangkou/Window.js"/> <script type="text/ecmascript" xlink:href="../chuangkou/textbox.js"/> <script type="text/ecmascript" xlink:href="../chuangkou/button.js"/> <script type="text/ecmascript"><![CDATA[ var myMapApp = new mapApp(); function init(evt) { myMapApp.Windows = new Array(); myMapApp.textbox=new Array(); var winPlaceholderStyles = {"fill":"none","stroke":"dimgray","stroke-width":1.5}; var windowStyles = {"fill":"aliceblue","stroke":"dimgray","stroke-width":1}; var titlebarStyles = {"fill":"gainsboro","stroke":"dimgray","stroke-width":1}; var statusbarStyles = {"fill":"aliceblue","stroke":"dimgray","stroke-width":1}; var titletextStyles = {"font-family":"Arial,Helvetica","font-size":14,"fill":"dimgray"}; var statustextStyles ={"font-family":"Arial,Helvetica","font-size":10,"fill":"dimgray"}; var buttonStyles = {"fill":"none","stroke":"dimgray","stroke-width":1}; var titlebarHeight = 25; var statusbarHeight = 13;//对话框 var textStyles = {"font-family":"Arial,Helvetica","font-size":15,"fill":"dimgray"}; var boxStyles = {"fill":"white","stroke":"dimgray","stroke-width":1.5}; var cursorStyles = {"stroke":"red","stroke-width":1.5}; var selBoxStyles = {"fill":"blue","opacity":0.5}; myMapApp.textbox = new textbox("textbox1","textbox1","",25,180,75,100,30,22,textStyles,boxStyles,cursorStyles,selBoxStyles,"[a-zA-Z ]",undefined); //文本框 var textStyles = {"font-family":"Arial,Helvetica","font-size":15,"fill":"dimgray"}; var boxStyles = {"fill":"white","stroke":"dimgray","stroke-width":1.5}; var cursorStyles = {"stroke":"red","stroke-width":1.5}; var selBoxStyles = {"fill":"blue","opacity":0.5}; myMapApp.textbox = new textbox("textbox2","textbox2","",25,180,120,100,30,22,textStyles,boxStyles,cursorStyles,selBoxStyles,"[a-zA-Z ]",undefined); //文本框 myMapApp.Windows["bigWindow"] = new Window("bigWindow","Windows", 400,300,50,150,true,0,80,1024,700,true, winPlaceholderStyles,windowStyles,3,true,true, "","This is a big movable window",true,true,true, titlebarStyles,titlebarHeight,statusbarStyles,statusbarHeight, titletextStyles,statustextStyles,buttonStyles,windowEvents); myMapApp.Windows["bigWindow"].appendContent("textbox1",true); myMapApp.Windows["bigWindow"].appendContent("mingcheng",true); myMapApp.Windows["bigWindow"].appendContent("zhuangtai",true); myMapApp.Windows["bigWindow"].appendContent("textbox2",true); myMapApp.Windows["bigWindow"].appendContent("queding",true); myMapApp.Windows["bigWindow"].appendContent("quxiao",true); } function windowEvents(id,evtType) { } ]]></script> <text id="mingcheng" x="50" y="100" style="font-size:20">名称</text> <text id="zhuangtai" x="50" y="140" style="font-size:20">连接状态</text> <text id="queding" x="50" y="250" style="fill:red; font-size:20px; font-weight:bold;">确定</text> <text id="quxiao" x="250" y="250" style="fill:red; font-size:20px; font-weight:bold;">取消</text> </svg> 我不知道如何实现这两svg文件的交互,或者怎么把定义的对话框直接在第一个svg文件中编写,希望大家多帮忙,头疼啊,谢谢~~~
|