SVG java.html的超链接

Hyperlink to SVG java/html

本文关键字:超链接 html java SVG      更新时间:2023-09-26

我一直在尝试将一个超链接与从amcharts.com下载的java地图上的一个SVG关联起来。代码是:

// svg path for target icon                 
var targetSVG = "M9,0C4.029,0,0,4.029,0,9s4.029,9,9,9s9-4.029,9-9S13.971,0,9,0z M9,15.93 c-3.83,0-6.93-3.1-6.93-6.93S5.17,2.07,9,2.07s6.93,3.1,6.93,6.93S12.83,15.93,9,15.93 M12.5,9c0,1.933-1.567,3.5-3.5,3.5S5.5,10.933,5.5,9S7.067,5.5,9,5.5 S12.5,7.067,12.5,9z";
targetSVG.onclick = function() {
  self.location.href = "http://www.google.com";
}
<link rel="stylesheet" href="../ammap/ammap.css" type="text/css">
<script src="../ammap/ammap.js" type="text/javascript"></script>
<!-- map file should be included after ammap.js -->
<script src="../ammap/maps/js/worldLow.js" type="text/javascript"></script>
<!-- scripts for exporting chart as an image -->
<!-- Note, the exporting will work only if you view the file from web server -->
<!-- Exporting to image works on all modern browsers except IE9 (IE10 works fine) -->
<!--[if (!IE) | (gte IE 10)]> -->
<script src="../ammap/exporting/amexport.js" type="text/javascript"></script>
<script src="../ammap/exporting/rgbcolor.js" type="text/javascript"></script>
<script src="../ammap/exporting/canvg.js" type="text/javascript"></script>
<script src="../ammap/exporting/filesaver.js" type="text/javascript"></script>
<!-- <![endif]-->
<script type="text/javascript">

我正在为我为"targetSVG.onclick"创建的最后一个函数寻找解决方案,但它似乎不起作用。我是javascript和此类应用程序的新手。请帮忙。

Mushi

由于SVG图像显示在Ammap中,因此您可以利用可用的属性并将url插入单个点定义中。

一个例子:

var city = {
id: "city",
color: "#000000",
svgPath: targetSVG,
url: "http://www.google.com",
urlTarget: "_blank",
latitude: 41.872389,
longitude: 12.48018,
scale: 1.5,
zoomLevel: 7.74,
zoomLongitude: 12.48018,
zoomLatitude: 41.872389,
} 

看看这个http://jsfiddle.net/aberna/L0h3eg74/1/演示

您可以在此处找到更多文档(http://docs.amcharts.com/javascriptmaps/MapObject)