有马萨诸塞州的SVG地图,想让每个县点击链接到外页

时间:2016-07-10 20:57:56

标签: html svg

我有一张马萨诸塞州的SVG地图,其中列出了各个县(来源可在此处找到:http://libremap.org/data/boundary/2000/county/svg/co25_d00.svg)。我已更改代码以在xlink:href标记中包含svg定义。我在基本的HTML文件中使用了SVG,如下所示:



<html>
<head>
	<title>SVG Test</title>
</head>
<body>
	<img src="co25_d00.svg" />
</body>
</html>
&#13;
&#13;
&#13;

图像加载正常,我可以根据需要更改每个县的填充。问题是我在特定a xlink:href周围放置了path,并且它不作为链接工作。以下是SVG代码的示例:

&#13;
&#13;
<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 20000303 Stylable//EN"
	"http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd">

<svg
   xmlns:svg="http://www.w3.org/2000/svg"
   xmlns="http://www.w3.org/2000/svg"
   xmlns:xlink="http://www.w3.org/1999/xlink"
   xmlns:a="http://ns.adobe.com/AdobeSVGViewerExtensions/3.0/"
   version="1.0" width="100%" height="100%" preserveAspectRatio="xMidYMax" viewBox="12.711167 456.567074 29.566845 18.433033">
<title>Libre Map Project</title>
<g transform="scale(1.0,-1.0) translate(0,-931.567181)">
<g id="Unknown_Area_Type_co25_d00_e00" style="fill:none;stroke:rgb(1,0,0);stroke-width:0.01;stroke-linecap:round">
  ...
  <a xlink:href="https://en.wikipedia.org/wiki/Barnstable_County,_Massachusetts"><path id="Barnstable" d="M37.230740 462.99185L37.268016 462.92386 37.375500 462.78861 37.391948 462.76791 37.559158 462.59886 37.582781 462.57499 37.603301 462.55942 37.664784 462.51279 37.673197 462.50641 37.729754 462.46353 37.747012 462.45044 37.767412 462.43498 37.966563 462.35378 38.126619 462.28857 38.255376 462.23615 38.499528 462.18269 38.523103 462.17754 38.563161 462.16877 38.621224 462.16374 39.024716 462.12888 39.264138 462.10831 39.286741 462.09215 39.385481 462.02160 39.391843 462.01706 39.393810 462.01566 39.395480 462.01184 39.401072 461.99905 39.403738 461.99295 39.417259 461.96204 39.487907 461.88070 39.505240 461.87960 39.508894 461.87937 39.524892 461.87837 39.541570 461.89592 39.590233 461.94715 39.626765 461.98561 39.664871 462.02574 39.717661 462.08135 39.728769 462.09305 39.730651 462.09503 39.819832 462.15186 39.843028 462.16665 39.888260 462.19548 40.112647 462.29230 40.114578 462.29188 40.114924 462.29181 40.172158 462.27930 40.181864 462.28209 40.183292 462.28250 40.224336 462.29431 40.362480 462.33408 40.510593 462.37675 40.614984 462.36658 40.662071 462.36200 40.672975 462.36094 40.731035 462.38313 40.733204 462.38396 40.785031 462.40378 40.839923 462.42477 40.870396 462.43643 40.889517 462.44374 40.967976 462.46347 41.009909 462.47401 41.126383 462.50331 41.137370 462.50608 41.143929 462.50773 41.154268 462.51033 41.187071 462.52591 41.292085 462.57578 41.328169 462.59293 41.414383 462.63390 41.419586 462.63637 41.485150 462.66754 41.496469 462.67972 41.506157 462.69014 41.607866 462.79962 41.617398 462.80988 41.618228 462.81078 41.622110 462.81496 41.660285 462.89775 41.661494 462.90038 41.661175 462.97599 41.660079 463.23692 41.648701 463.38323 41.638199 463.51834 41.627424 463.65703 41.658143 463.70385 41.701988 463.77068 41.679743 463.80844 41.603329 463.82423 41.503226 463.90497 41.500326 463.95440 41.494832 464.04808 41.459389 464.22463 41.455827 464.24238 41.336076 464.25377 41.257202 464.22494 41.162114 464.05168 41.160025 463.91826 41.160449 463.87381 41.161291 463.78568 41.162725 463.77090 41.170764 463.68808 41.154588 463.66703 41.141720 463.67588 41.114865 463.73373 41.099359 463.92060 41.096743 464.35224 41.087791 464.56613 41.074973 464.87274 41.063677 464.94094 41.030280 465.14268 41.026069 465.16812 40.979835 465.31146 40.931150 465.40021 40.829518 465.52111 40.706690 465.61230 40.507976 465.72432 40.499265 465.72924 40.440416 465.73513 40.321148 465.70706 40.263076 465.67832 40.248763 465.67123 40.192204 465.61844 40.178766 465.60590 40.147844 465.54825 40.113840 465.48487 40.107646 465.44033 40.105658 465.42604 40.123437 465.35265 40.178593 465.28227 40.174957 465.26673 40.140814 465.26858 40.092678 465.29592 40.000236 465.38940 39.914177 465.55851 39.795619 465.69199 39.749570 465.72336 39.710985 465.72492 39.696231 465.76028 39.758083 465.86094 39.862078 465.92300 40.017500 465.95742 40.163093 465.96024 40.403550 465.91574 40.451802 465.89891 40.767552 465.78885 41.041587 465.64117 41.238988 465.47997 41.283325 465.42483 41.436045 465.23499 41.443119 465.22620 41.448436 465.21669 41.539002 465.05474 41.618306 464.91300 41.737306 464.65747 41.826993 464.46502 41.846264 464.40692 41.967179 464.04260 42.055474 463.68904 42.112508 463.46086 42.152151 463.30235 42.224626 462.90901 42.225544 462.90403 42.254156 462.49063 42.255592 462.46990 42.278008 462.14648 42.277262 461.99368 42.276992 461.93830 42.275328 461.59632 42.246321 461.43415 42.232334 461.35599 42.153595 461.18265 42.126727 461.12353 42.108747 461.08396 42.092088 461.05609 42.080885 461.03734 42.078456 461.03327 42.069716 461.03113 42.034061 461.02238 42.019131 461.01872 41.977108 460.95661 41.937715 460.88720 41.863011 460.62335 41.807826 460.38133 41.761107 460.09397 41.759877 460.08641 41.758979 460.08089 41.756989 460.07799 41.675367 459.95911 41.624583 459.94271 41.563231 459.95235 41.538949 459.98162 41.521884 460.03998 41.533689 460.06266 41.534898 460.06498 41.536689 460.06477 41.554630 460.06269 41.571673 460.06072 41.648873 460.16265 41.710592 460.32730 41.736248 460.46876 41.774158 460.67787 41.774350 460.67893 41.807197 460.77556 41.810965 460.78664 41.832755 460.85076 41.841612 460.87683 41.860972 460.93381 41.895303 461.03488 41.896380 461.03805 41.896134 461.10375 41.875621 461.17921 41.833157 461.21695 41.829289 461.22039 41.705485 461.33046 41.673236 461.34870 41.617378 461.38029 41.570248 461.38426 41.566380 461.38459 41.557494 461.38534 41.430945 461.33991 41.363606 461.33078 41.360911 461.33041 41.212630 461.31033 41.133231 461.30494 40.954581 461.29284 40.931660 461.29129 40.692202 461.21804 40.659560 461.20806 40.584445 461.18511 40.499917 461.15929 40.429241 461.16031 40.355074 461.16139 40.352163 461.16143 40.081236 461.10761 40.080954 461.10750 40.055456 461.09750 40.054438 461.09710 39.837307 461.01201 39.709151 460.96182 39.622129 460.92776 39.534713 460.84262 39.540785 460.80748 39.504869 460.73384 39.456101 460.71756 39.438335 460.73536 39.421959 460.81181 39.427901 460.90020 39.415122 460.92370 39.384163 460.98063 39.327902 461.00588 39.250452 461.00782 39.128208 460.98506 38.991718 460.95968 38.988393 460.96191 38.986389 460.96326 38.922978 461.00593 38.898825 461.01330 38.889072 461.01627 38.855456 461.02652 38.742169 461.00995 38.668921 460.97093 38.630340 460.92325 38.630937 460.89421 38.631037 460.88937 38.587094 460.80363 38.508831 460.75461 38.329374 460.70220 38.324663 460.70304 38.323971 460.70317 38.281913 460.71065 38.263268 460.71397 38.240457 460.71222 38.231006 460.71149 38.061163 460.69842 38.023653 460.69554 37.954117 460.54662 37.932408 460.51179 37.907014 460.47106 37.841406 460.36585 37.831832 460.35050 37.817093 460.32687 37.805205 460.31327 37.798903 460.30606 37.742189 460.24118 37.736757 460.23496 37.689687 460.18113 37.615246 460.13756 37.611195 460.13519 37.607828 460.13397 37.546783 460.11187 37.491132 460.10500 37.303630 460.08192 37.258022 460.08169 37.225862 460.08153 37.096172 460.08091 36.991890 460.08043 36.985980 460.07972 36.902912 460.06975 36.869961 460.06581 36.812554 460.05893 36.748724 460.05129 36.746101 460.05098 36.705570 460.04613 36.683542 460.04350 36.598991 460.03339 36.562151 460.02900 36.528379 460.02022 36.519722 460.01797 36.500602 460.01301 36.465170 460.00381 36.373264 459.97995 36.300327 459.92502 36.294511 459.92064 36.288433 459.91607 36.276589 459.89685 36.261510 459.87240 36.200456 459.77338 36.198195 459.76972 36.157548 459.74315 36.115754 459.71583 36.068355 459.70906 36.068355 459.70906 36.046056 459.73654 36.026864 459.77702 35.970136 459.75774 35.911927 459.75042 35.887030 459.76260 35.861232 459.84883 35.860061 459.84974 35.860061 459.84974 35.928998 459.89288 35.969121 459.91800 36.094434 459.99646 36.108047 460.00499 36.141812 460.02614 36.148183 460.03013 36.163243 460.03957 36.165379 460.04090 36.179187 460.06722 36.203113 460.11283 36.195859 460.19707 36.209713 460.28190 36.253396 460.33338 36.304221 460.36034 36.309991 460.37996 36.317944 460.40699 36.320271 460.41490 36.312380 460.47882 36.310798 460.48359 36.310226 460.48531 36.274985 460.59158 36.259328 460.63881 36.230318 460.72633 36.231908 460.74416 36.235234 460.78148 36.282818 460.85469 36.322052 460.91506 36.332852 460.93169 36.338130 460.93981 36.301594 461.02715 36.296303 461.03980 36.291073 461.04402 36.235884 461.08852 36.252979 461.14981 36.255520 461.15892 36.297071 461.18255 36.343326 461.20885 36.354262 461.21507 36.364202 461.27204 36.353661 461.31381 36.353579 461.31414 36.312254 461.47792 36.297018 461.53833 36.272770 461.56667 36.171485 461.57765 36.303156 461.70882 36.474961 461.75995 36.479421 461.78569 36.482194 461.80170 36.491661 461.85634 36.468905 461.91893 36.436396 461.93401 36.333448 461.98178 36.333448 461.98178 36.356782 462.03895 36.365084 462.08776 36.365084 462.08776 36.365785 462.09920 36.365785 462.09920 36.422913 462.14930 36.417572 462.16948 36.422730 462.19486 36.422730 462.19486 36.480110 462.27385 36.492775 462.27851 36.492775 462.27851 36.516764 462.28866 36.520350 462.29491 36.523909 462.30147 36.522167 462.31009 36.483238 462.38742 36.483238 462.38742 36.463404 462.42486 36.463404 462.42486 36.453382 462.44371 36.453382 462.44371 36.429461 462.47330 36.429461 462.47330 36.669431 462.59560 36.859916 462.67466 36.961174 462.71628 36.993330 462.72788 37.033600 462.77391 37.146083 462.89660 37.159201 462.91208 37.230740 462.99185Z"/></a>
  ...
</g>
</g>
</svg>
&#13;
&#13;
&#13;

我在codepen,jsfiddle和其他各种类似的设置上看到的代码片段,我不知道为什么它不能正常工作。任何指针都非常感谢!

1 个答案:

答案 0 :(得分:2)

它不起作用的原因是因为如果nonefill,则点击不会注册。使用transparent <?xml version="1.0" encoding="iso-8859-1"?> <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 20000303 Stylable//EN" "http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd"> <svg xmlns:svg="http://www.w3.org/2000/svg" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:a="http://ns.adobe.com/AdobeSVGViewerExtensions/3.0/" version="1.0" width="100%" height="100%" preserveAspectRatio="xMidYMax" viewBox="12.711167 456.567074 29.566845 18.433033"> <title>Libre Map Project</title> <g transform="scale(1.0,-1.0) translate(0,-931.567181)"> <g id="Unknown_Area_Type_co25_d00_e00" style="fill:transparent;stroke:rgb(1,0,0);stroke-width:0.01;stroke-linecap:round"> ... <a xlink:href="https://en.wikipedia.org/wiki/Barnstable_County,_Massachusetts"><path id="Barnstable" d="M37.230740 462.99185L37.268016 462.92386 37.375500 462.78861 37.391948 462.76791 37.559158 462.59886 37.582781 462.57499 37.603301 462.55942 37.664784 462.51279 37.673197 462.50641 37.729754 462.46353 37.747012 462.45044 37.767412 462.43498 37.966563 462.35378 38.126619 462.28857 38.255376 462.23615 38.499528 462.18269 38.523103 462.17754 38.563161 462.16877 38.621224 462.16374 39.024716 462.12888 39.264138 462.10831 39.286741 462.09215 39.385481 462.02160 39.391843 462.01706 39.393810 462.01566 39.395480 462.01184 39.401072 461.99905 39.403738 461.99295 39.417259 461.96204 39.487907 461.88070 39.505240 461.87960 39.508894 461.87937 39.524892 461.87837 39.541570 461.89592 39.590233 461.94715 39.626765 461.98561 39.664871 462.02574 39.717661 462.08135 39.728769 462.09305 39.730651 462.09503 39.819832 462.15186 39.843028 462.16665 39.888260 462.19548 40.112647 462.29230 40.114578 462.29188 40.114924 462.29181 40.172158 462.27930 40.181864 462.28209 40.183292 462.28250 40.224336 462.29431 40.362480 462.33408 40.510593 462.37675 40.614984 462.36658 40.662071 462.36200 40.672975 462.36094 40.731035 462.38313 40.733204 462.38396 40.785031 462.40378 40.839923 462.42477 40.870396 462.43643 40.889517 462.44374 40.967976 462.46347 41.009909 462.47401 41.126383 462.50331 41.137370 462.50608 41.143929 462.50773 41.154268 462.51033 41.187071 462.52591 41.292085 462.57578 41.328169 462.59293 41.414383 462.63390 41.419586 462.63637 41.485150 462.66754 41.496469 462.67972 41.506157 462.69014 41.607866 462.79962 41.617398 462.80988 41.618228 462.81078 41.622110 462.81496 41.660285 462.89775 41.661494 462.90038 41.661175 462.97599 41.660079 463.23692 41.648701 463.38323 41.638199 463.51834 41.627424 463.65703 41.658143 463.70385 41.701988 463.77068 41.679743 463.80844 41.603329 463.82423 41.503226 463.90497 41.500326 463.95440 41.494832 464.04808 41.459389 464.22463 41.455827 464.24238 41.336076 464.25377 41.257202 464.22494 41.162114 464.05168 41.160025 463.91826 41.160449 463.87381 41.161291 463.78568 41.162725 463.77090 41.170764 463.68808 41.154588 463.66703 41.141720 463.67588 41.114865 463.73373 41.099359 463.92060 41.096743 464.35224 41.087791 464.56613 41.074973 464.87274 41.063677 464.94094 41.030280 465.14268 41.026069 465.16812 40.979835 465.31146 40.931150 465.40021 40.829518 465.52111 40.706690 465.61230 40.507976 465.72432 40.499265 465.72924 40.440416 465.73513 40.321148 465.70706 40.263076 465.67832 40.248763 465.67123 40.192204 465.61844 40.178766 465.60590 40.147844 465.54825 40.113840 465.48487 40.107646 465.44033 40.105658 465.42604 40.123437 465.35265 40.178593 465.28227 40.174957 465.26673 40.140814 465.26858 40.092678 465.29592 40.000236 465.38940 39.914177 465.55851 39.795619 465.69199 39.749570 465.72336 39.710985 465.72492 39.696231 465.76028 39.758083 465.86094 39.862078 465.92300 40.017500 465.95742 40.163093 465.96024 40.403550 465.91574 40.451802 465.89891 40.767552 465.78885 41.041587 465.64117 41.238988 465.47997 41.283325 465.42483 41.436045 465.23499 41.443119 465.22620 41.448436 465.21669 41.539002 465.05474 41.618306 464.91300 41.737306 464.65747 41.826993 464.46502 41.846264 464.40692 41.967179 464.04260 42.055474 463.68904 42.112508 463.46086 42.152151 463.30235 42.224626 462.90901 42.225544 462.90403 42.254156 462.49063 42.255592 462.46990 42.278008 462.14648 42.277262 461.99368 42.276992 461.93830 42.275328 461.59632 42.246321 461.43415 42.232334 461.35599 42.153595 461.18265 42.126727 461.12353 42.108747 461.08396 42.092088 461.05609 42.080885 461.03734 42.078456 461.03327 42.069716 461.03113 42.034061 461.02238 42.019131 461.01872 41.977108 460.95661 41.937715 460.88720 41.863011 460.62335 41.807826 460.38133 41.761107 460.09397 41.759877 460.08641 41.758979 460.08089 41.756989 460.07799 41.675367 459.95911 41.624583 459.94271 41.563231 459.95235 41.538949 459.98162 41.521884 460.03998 41.533689 460.06266 41.534898 460.06498 41.536689 460.06477 41.554630 460.06269 41.571673 460.06072 41.648873 460.16265 41.710592 460.32730 41.736248 460.46876 41.774158 460.67787 41.774350 460.67893 41.807197 460.77556 41.810965 460.78664 41.832755 460.85076 41.841612 460.87683 41.860972 460.93381 41.895303 461.03488 41.896380 461.03805 41.896134 461.10375 41.875621 461.17921 41.833157 461.21695 41.829289 461.22039 41.705485 461.33046 41.673236 461.34870 41.617378 461.38029 41.570248 461.38426 41.566380 461.38459 41.557494 461.38534 41.430945 461.33991 41.363606 461.33078 41.360911 461.33041 41.212630 461.31033 41.133231 461.30494 40.954581 461.29284 40.931660 461.29129 40.692202 461.21804 40.659560 461.20806 40.584445 461.18511 40.499917 461.15929 40.429241 461.16031 40.355074 461.16139 40.352163 461.16143 40.081236 461.10761 40.080954 461.10750 40.055456 461.09750 40.054438 461.09710 39.837307 461.01201 39.709151 460.96182 39.622129 460.92776 39.534713 460.84262 39.540785 460.80748 39.504869 460.73384 39.456101 460.71756 39.438335 460.73536 39.421959 460.81181 39.427901 460.90020 39.415122 460.92370 39.384163 460.98063 39.327902 461.00588 39.250452 461.00782 39.128208 460.98506 38.991718 460.95968 38.988393 460.96191 38.986389 460.96326 38.922978 461.00593 38.898825 461.01330 38.889072 461.01627 38.855456 461.02652 38.742169 461.00995 38.668921 460.97093 38.630340 460.92325 38.630937 460.89421 38.631037 460.88937 38.587094 460.80363 38.508831 460.75461 38.329374 460.70220 38.324663 460.70304 38.323971 460.70317 38.281913 460.71065 38.263268 460.71397 38.240457 460.71222 38.231006 460.71149 38.061163 460.69842 38.023653 460.69554 37.954117 460.54662 37.932408 460.51179 37.907014 460.47106 37.841406 460.36585 37.831832 460.35050 37.817093 460.32687 37.805205 460.31327 37.798903 460.30606 37.742189 460.24118 37.736757 460.23496 37.689687 460.18113 37.615246 460.13756 37.611195 460.13519 37.607828 460.13397 37.546783 460.11187 37.491132 460.10500 37.303630 460.08192 37.258022 460.08169 37.225862 460.08153 37.096172 460.08091 36.991890 460.08043 36.985980 460.07972 36.902912 460.06975 36.869961 460.06581 36.812554 460.05893 36.748724 460.05129 36.746101 460.05098 36.705570 460.04613 36.683542 460.04350 36.598991 460.03339 36.562151 460.02900 36.528379 460.02022 36.519722 460.01797 36.500602 460.01301 36.465170 460.00381 36.373264 459.97995 36.300327 459.92502 36.294511 459.92064 36.288433 459.91607 36.276589 459.89685 36.261510 459.87240 36.200456 459.77338 36.198195 459.76972 36.157548 459.74315 36.115754 459.71583 36.068355 459.70906 36.068355 459.70906 36.046056 459.73654 36.026864 459.77702 35.970136 459.75774 35.911927 459.75042 35.887030 459.76260 35.861232 459.84883 35.860061 459.84974 35.860061 459.84974 35.928998 459.89288 35.969121 459.91800 36.094434 459.99646 36.108047 460.00499 36.141812 460.02614 36.148183 460.03013 36.163243 460.03957 36.165379 460.04090 36.179187 460.06722 36.203113 460.11283 36.195859 460.19707 36.209713 460.28190 36.253396 460.33338 36.304221 460.36034 36.309991 460.37996 36.317944 460.40699 36.320271 460.41490 36.312380 460.47882 36.310798 460.48359 36.310226 460.48531 36.274985 460.59158 36.259328 460.63881 36.230318 460.72633 36.231908 460.74416 36.235234 460.78148 36.282818 460.85469 36.322052 460.91506 36.332852 460.93169 36.338130 460.93981 36.301594 461.02715 36.296303 461.03980 36.291073 461.04402 36.235884 461.08852 36.252979 461.14981 36.255520 461.15892 36.297071 461.18255 36.343326 461.20885 36.354262 461.21507 36.364202 461.27204 36.353661 461.31381 36.353579 461.31414 36.312254 461.47792 36.297018 461.53833 36.272770 461.56667 36.171485 461.57765 36.303156 461.70882 36.474961 461.75995 36.479421 461.78569 36.482194 461.80170 36.491661 461.85634 36.468905 461.91893 36.436396 461.93401 36.333448 461.98178 36.333448 461.98178 36.356782 462.03895 36.365084 462.08776 36.365084 462.08776 36.365785 462.09920 36.365785 462.09920 36.422913 462.14930 36.417572 462.16948 36.422730 462.19486 36.422730 462.19486 36.480110 462.27385 36.492775 462.27851 36.492775 462.27851 36.516764 462.28866 36.520350 462.29491 36.523909 462.30147 36.522167 462.31009 36.483238 462.38742 36.483238 462.38742 36.463404 462.42486 36.463404 462.42486 36.453382 462.44371 36.453382 462.44371 36.429461 462.47330 36.429461 462.47330 36.669431 462.59560 36.859916 462.67466 36.961174 462.71628 36.993330 462.72788 37.033600 462.77391 37.146083 462.89660 37.159201 462.91208 37.230740 462.99185Z"/></a> ... </g> </g> </svg>进行尝试。

&#13;
&#13;
var svg = d3.select("body").append("svg")
    .attr("width", width)
    .attr("height", height)
    .attr("id", "map");

var g = svg.append("g")
    .call(zoom);

var map = g.append("g")
    .attr("transform", "translate(0,0) scale(1)");
&#13;
&#13;
&#13;