2011-10-28 123 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。