2011-10-28 43 views
23

我已经看到了几个线程来解决这个问题,但没有真正解决我的问题。我有一个带有地图和不同区域的SVG文件(http://www.mediafire.com/?5pmyevdwbyrb51f)。我想要做这样的事情:http://raphaeljs.com/australia.htmlRaphael JS - 使用SVG文件

但问题是我如何转换文件,以便在脚本中工作?我如何获得这些坐标?我尝试了几个转换器等,但我必须吮吸这个因为我不能得到它的工作。也许有人可以帮忙吗?

+0

[Raphael中的SVG文件可能重复吗?](http://stackoverflow.com/questions/3135061/svg-files-in-raphael-can-they-be-used) –

回答

2

看的代码:

http://raphaeljs.com/tiger.html

<script src="tiger.js"> 
// Load the file with the tiger mapping to a variable 
    var tiger = [0,0,600,600,{type:"path",path:"M-122.304 84.285C-12... 
</script> 

<script> 
// run it 
window.onload = function() { 
    var r = Raphael(tiger).translate(200, 200); 
}; 
</script> 
+0

我不dont看看这对我有什么帮助。那个例子不使用SVG文件?如果我现在很愚蠢,请向我解释一下。问题是从我的文件中获取这些坐标(如tiger.js中的坐标)。 – larschanders

+1

https://github.com/crccheck/raphael-svg-import-classic – fmsf

+0

使用此解决方案,您必须将.svg文件中的AJAX作为.txt并将路径数据提供给Raphael。这实际上是一个相当不错的解决方案 – netpoetica

9

如果你的意思是使用拉斐尔导入SVG文件,以便您可以显示它或操纵它,它目前还不支持。但你可能想检查扩展raphael-svg-importraphael-svg-import-classic

SVG files in Raphael, can they be used?

+0

感谢您的答案。已经尝试过,但无法让他们工作。如果有人觉得他们想尝试一下,我在我的第一篇文章中有链接到我的文件。不知道我做错了什么。在InkScape中尝试了不同的“设置”,但这不是我的一杯茶... – larschanders

+0

我也尝试过转换器[这里](https://github.com/wout/raphael-svg-import),但你需要写下你的svg文件的全部内容,它不会接受inkscape生成的任何svg格式。 –

0

另外见到mikefrey's answer使用说唱,一个例子:

var paper = Raphael(0, 0, 160, 600); 

var rappar = [...]; // here use the output from rappar 

var graphic = paper.set(); 
rappar.forEach(function (item) { 
    graphic.push(paper 
    .path(item.path) 
    .attr('fill', item.fill) 
    .attr('stroke', item.stroke) 
    // ... 
); 
}); 
graphic.transform('s0.8,0.8,0,0'); 
// ... 

使用圣拉斐尔V2.2.6和rappar v0.0.2。