SVG files in Raphael, can they be used?

天大地大妈咪最大 提交于 2019-12-19 05:48:53

问题


I have an SVG file that I would like to display via Raphael (each svg file is a node in a tree I'm trying to draw, the actual connections of the tree will be made by raphael). I tried something like:

var vector_image = paper.image("test.svg", 50,50,50,50);

but no dice, seems only "real" image files like png or jpeg are accepted? I find this very strange as Raphael itself uses Scalable Vector Graphics.

Is there anyway (short of parsing the SVG files into javascript snippets and pasting them into the html document) to display existing SVG files using Raphael (or any other vector based javascript graphical engine?)

If parsing it will have to be, is there any easy way to do this, short of just manually scraping the files? I'm running this code on a Ruby on Rails server, so I'd like to avoid solutions outside this framework, if possible (I've heard of one PHP solution through this site...I'd rather code by hand than add another language onto this project).

-Jenny


回答1:


It's currently not possible to display existing SVG with Raphael, and there are apparently no plans for the implementation of SVG editing (see this forum post). As for alternative JavaScript libraries, a newer alternative is Snap.svg, which can load external SVG files via its Snap.load() function.



来源:https://stackoverflow.com/questions/3135061/svg-files-in-raphael-can-they-be-used

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!