以文本方式查看主题

-  中文XML论坛 - 专业的XML技术讨论区  (http://bbs.xml.org.cn/index.asp)
--  『 SVG/GML/VRML/X3D/XAML 』  (http://bbs.xml.org.cn/list.asp?boardid=21)
----  用了一天,终于解决了在SVG下鼠标提示框正常显示问题  (http://bbs.xml.org.cn/dispbbs.asp?boardid=21&rootid=&id=37991)


--  作者:chilong_zh
--  发布时间:9/17/2006 10:28:00 AM

--  用了一天,终于解决了在SVG下鼠标提示框正常显示问题
在SVG中如何显示鼠标提示框
SVG代码如下:
<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 20010904//EN"
  "http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd">
<svg width="100%" height="100%" onload ="getSVGDoc(evt)"  onzoom="ZoomControl()">
  <script xlink:href="tool_tip.js" type="text/javascript"/>
  <g id="testG" onmouseover = "ShowTooltip(evt, 'Welcome To Here!')" onmouseout = "HideTooltip(evt)">
    <rect x="100" y="100" width="100" height="50" style="fill:rgb(120,255,255);"/>
  </g>
  <g id="tooltip" style="pointer-events: none">
    <rect id="ttr" x="0" y="0" rx="5" ry="5" width="100" height="16"
      style="visibility: hidden"/>
    <text id="ttt" x="0" y="0" style="visibility: hidden">dyn. Text</text>
  </g>
</svg>
在SVG中使用的脚步文件tool_tip.js如下:
var svgdoc, svgroot, ttrelem, tttelem, tt;

function getSVGDoc(load_evt)
{
  svgdoc = load_evt.target.ownerDocument;
  svgroot = svgdoc.documentElement;
  ttrelem = svgdoc.getElementById("ttr");
  tttelem = svgdoc.getElementById("ttt");
  // tt=svgdoc.getElementById("tooltip");
}

function ShowTooltip(e, txt)
{
  var posx, posy, curtrans, ctx, cty;
  
  posx = e.clientX;
  posy = e.clientY;
  curtrans = svgroot.currentTranslate;
  ctx = curtrans.x;
  cty = curtrans.y;
  
  tttelem.childNodes.item(0).data = txt;
  ttrelem.setAttribute("x", posx - ctx + 5);
  ttrelem.setAttribute("y", posy - cty + 20);
  tttelem.setAttribute("x", posx - ctx + 10);
  tttelem.setAttribute("y", posy - cty + 32);
  ttrelem.setAttribute("width", tttelem.getComputedTextLength() + 10);
  tttelem.setAttribute("style", "fill: #0000CC; font-size: 11px; visibility: visible");
  ttrelem.setAttribute("style", "fill: #FFFFCC; stroke: #000000; stroke-width: 0.5px; visibility: visible");
}

function HideTooltip()
{
  // tt.style.setProperty("visibility","hidden","");
  ttrelem.setAttribute("style", "visibility: hidden");
  tttelem.setAttribute("style", "visibility: hidden");
}

function ZoomControl()
{
  var curzoom;
  curzoom = svgroot.currentScale;
  svgdoc.getElementById("tooltip").setAttribute("transform","scale("+1/curzoom+")");
}
在IE6中显示如下图:

此主题相关图片如下:
按此在新窗口浏览图片
在这里解决的由于平移和缩放后造成提示框相应平移和缩放的bug。


--  作者:wwwtiger
--  发布时间:9/18/2006 8:50:00 AM

--  
谢谢分享
--  作者:tamefox
--  发布时间:9/20/2006 3:12:00 PM

--  
good!
--  作者:yaohuhuowu
--  发布时间:9/21/2006 10:47:00 AM

--  
怎么实现在那个弹出窗口显示中文内容呀???用中文就是乱码
--  作者:chilong_zh
--  发布时间:9/21/2006 10:33:00 PM

--  
to yaohuhuowu:
非常抱歉,在消息里的回答有误,在没有证实前做出轻率的回答。我在这里也不能正常显示。现在找办法,如何你有好办法记得通知我一声。
--  作者:chilong_zh
--  发布时间:9/22/2006 9:51:00 AM

--  
to yaohuhuowu:
现在已经可以正常显示中文,代码如下:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 20010904//EN"
  "http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd">
<svg width="100%" height="100%" onload ="getSVGDoc(evt)" onzoom="ZoomControl()" font-family="SimSun">

  <script type="text/javascript">
     <![CDATA[
        var svgdoc,svgroot,ttrelem,tttelem,tt;


function getSVGDoc(load_evt)
{
  svgdoc = load_evt.target.ownerDocument;
  svgroot = svgdoc.documentElement;
  ttrelem = svgdoc.getElementById("ttr");
  tttelem = svgdoc.getElementById("ttt");
  // tt=svgdoc.getElementById("tooltip");
}


function ShowTooltip(e, txt)
{
  var posx, posy, curtrans, ctx, cty;
  
  posx = e.clientX;
  posy = e.clientY;
  curtrans = svgroot.currentTranslate;
  ctx = curtrans.x;
  cty = curtrans.y;
  
  tttelem.childNodes.item(0).data = txt;
  ttrelem.setAttribute("x", posx-ctx);
  ttrelem.setAttribute("y", posy-cty-20);
  tttelem.setAttribute("x", posx-ctx+5);
  tttelem.setAttribute("y", posy-cty-8);
  ttrelem.setAttribute("width", tttelem.getComputedTextLength() + 10);
  tttelem.setAttribute("style", "fill: #0000CC; font-size: 11px; visibility: visible");
  ttrelem.setAttribute("style", "fill: #FFFFCC; stroke: #000000; stroke-width: 0.5px; visibility: visible");
}


function HideTooltip()
{
  // tt.style.setProperty("visibility","hidden","");
  ttrelem.setAttribute("style", "visibility: hidden");
  tttelem.setAttribute("style", "visibility: hidden");
}


function ZoomControl()
{
  var curzoom;
  curzoom = svgroot.currentScale;
  svgdoc.getElementById("tooltip").setAttribute("transform","scale("+1/curzoom+")");
}
     ]]>
  </script>

  <g id="testG" onmouseover = "ShowTooltip(evt, '欢迎')" onmouseout = "HideTooltip(evt)" >
    <rect x="100" y="100" width="100" height="50" style="fill:rgb(120,255,255);"/>
  </g>

  <g id="tooltip" style="pointer-events: none">
    <rect id="ttr" x="0" y="0" rx="5" ry="5" width="100" height="16"
      style="visibility: hidden"/>
    <text id="ttt" x="0" y="0" style="visibility: hidden">dyn. Text</text>
  </g>


</svg>

其中在第一行将encoding的属性改写为UTF-8,其次在SVG元素中添加font-family="SimSun"的属性就可以正常显示。


--  作者:chilong_zh
--  发布时间:9/22/2006 9:53:00 AM

--  
显示如下图:

此主题相关图片如下:
按此在新窗口浏览图片
--  作者:yaohuhuowu
--  发布时间:9/22/2006 8:59:00 PM

--  
to chilong_zh
中文能显示了,但是你的这个弹出框在有viewBox 属性的SVG当中弹出的位置变化相当大。我也找了资料发现应该利用脚本,把变换产生的坐标偏移给修正,具体实现实在是不清楚。还有我正打算利用哥哥的脚本把这个修改成,弹出一个大框,并且可以显示好几行字的东西,现在正在试验当中:)
--  作者:yaohuhuowu
--  发布时间:9/22/2006 10:34:00 PM

--  
呵呵分析了一下哥哥的代码现在小弟已经可以做出来弹出框是多行文字的了,谢谢哥哥。
--  作者:bluehxjing
--  发布时间:9/24/2006 10:21:00 PM

--  
有人做点击图形查看图形的信息,而这些信息是从数据库中得来的,有人做嘛?
--  作者:huangwanfu
--  发布时间:10/11/2006 10:10:00 AM

--  
改成UTF-8编码提示错误,
没有排的:
--  作者:with2000
--  发布时间:11/19/2006 1:47:00 AM

--  
这段代码在很多程序中都看到了!呵呵
--  作者:reallylove
--  发布时间:12/18/2006 9:45:00 AM

--  
不错,谢谢搂住!
--  作者:reallylove
--  发布时间:12/20/2006 9:53:00 AM

--  
提示框大小怎么改变???
--  作者:aone_
--  发布时间:12/20/2006 1:13:00 PM

--  
这段代码很久以前一个群里的朋友就发给过我,原做?
--  作者:ghu52937848
--  发布时间:3/24/2008 4:56:00 PM

--  
......
--  作者:wjlover
--  发布时间:3/25/2008 3:36:00 PM

--  
不错!
--  作者:lhappyb
--  发布时间:3/27/2008 3:56:00 PM

--  
我正在研究,我现在读从数据库出来的信息,需要安装GeoMieda Webmap,引用里面的类库实现
W 3 C h i n a ( since 2003 ) 旗 下 站 点
苏ICP备05006046号《全国人大常委会关于维护互联网安全的决定》《计算机信息网络国际联网安全保护管理办法》
105.469ms