我在 Inkscape 中绘制了一张地图,将其保存为 SVG 并使用http://readysetraphael.com/将其转换为 Raphial。我将此生成的代码放入一个名为的函数drawMap
中,并将其保存在 js/map.js
js/map.js:
function drawMap(){
var map = Raphael('map', '100mm', '100mm');
var layer4 = map.set();
var path3041 = map.path("m 106.15571,153.07817 -1.64315,13.74999 4.60661,10.36488 6.04618,9.21323 9.21323,3.16705 6.04618,6.04618 8.34949,8.06157 77.4487,1.72748 3.45496,-48.79108 z");
path3041.attr({id: 'path3041',parent: 'layer4',opacity: '0.98999999',fill: '#ffb380',stroke: '#000000',"stroke-width": '3',"stroke-linecap": 'butt',"stroke-linejoin": 'miter',"stroke-miterlimit": '4',"stroke-opacity": '1',"stroke-dasharray": 'none'}).data('id', 'path3041');
layer4.attr({'id': 'layer4','name': 'layer4'});
//etc, more lines than stackoverflow will let me add
var mapGroups = [layer4,layer5,layer19,layer20,layer21,layer22,layer23,layer24,layer25,layer26,layer6,layer7,layer8,layer9,layer10,layer1,layer3,layer11,layer12,layer13,layer14,layer15,layer16,layer17,layer18,layer27,layer28,layer29,layer30,layer31,layer32,layer33,layer34,layer35,layer36,layer37,layer38,layer39,layer40,layer41,layer42,layer43,layer44,layer45];
}
然后我把raphael-min.js
并放入'js'文件夹。
当我打电话给drawMap()
萤火虫说:
“未定义drawMap”
我将 map.js 的内容添加到 html 文件中,但收到错误“未定义 Raphial”。
我认为这是因为在加载之前调用了 raphial,raphial-min.js
所以我在调用之前使用了 Modernizer 来加载raphial-min.js
,但现在我得到了错误:map.ja
drawMap()
“未定义drawMap”
索引.html:
<!DOCTYPE html>
<html>
<head>
<title>Risk</title>
<script type="text/javascript" src="http://modernizr.com/downloads/modernizr.js"></script>
</head>
<body>
<div id="map">
<script type="text/javascript">
drawMap()
Modernizr.load({
load: 'js/raphael-min.js',
load: 'js/map.js',
complete: drawMap()
})
</script>
</div>
</body>
</html>