2011-10-28 16 views
23

Ho visto diversi thread che rispondono a questa domanda ma nulla che risolva veramente il mio problema. Ho un file SVG con una mappa e diverse regioni (http://www.mediafire.com/?5pmyevdwbyrb51f). Voglio fare qualcosa di simile a questo: http://raphaeljs.com/australia.html.Raphael JS - Usa un file SVG

Ma la domanda è come posso convertire il file in modo che funzioni nello script? Come ottengo quelle coordinate? Ho provato diversi convertitori e simili, ma devo fare schifo perché non riesco a farlo funzionare. Forse qualcuno può dare una mano?

+0

possibile duplicato di [file SVG in Raphael, possono essere utilizzati?] (Http://stackoverflow.com/questions/3135061/svg-files-in-raphael-can-the-be-used) –

risposta

2

sguardo al codice di:

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

I do not guarda come mi aiuta Questo esempio non usa un file SVG? Spiegami se sono stupido adesso. Il problema è ottenere quelle coordinate (come quelle in tiger.js) dal mio file. – larschanders

+1

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

+0

Con questa soluzione, è necessario AJAX nel proprio file .svg come .txt e inserire i dati del percorso da fornire a Raphael. In realtà è una soluzione abbastanza decente – netpoetica

9

se si intende utilizzare Raphael per importare un file in formato SVG in modo da poter visualizzare o manipolarla, non è attualmente supportato. Ma potresti voler controllare le estensioni raphael-svg-import o raphael-svg-import-classic.

Vedi anche SVG files in Raphael, can they be used?

+0

Grazie per la risposta. Li ho già provati e non riesco a farli funzionare. Se qualcuno sente di voler provare, ho il link al mio file nel mio primo post. Non so cosa sto facendo male. Ho provato con diverse "impostazioni" in InkScape, ma questa non è la mia tazza di tè ... – larschanders

+0

Ho anche provato il convertitore [qui] (https://github.com/wout/raphael-svg-import) ma è necessario per scrivere l'intero contenuto del tuo file SVG e non accetterà alcun formato SVG prodotto da inkscape. –

0

In aggiunta a mikefrey's answer utilizzando rapper, un esempio:

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'); 
// ... 

Utilizzando Raphael v2.2.6 e v0.0.2 rappar.

Problemi correlati