如何使用RaphaelJS绘制现有的矢量图像
我开始学习 RaphaelJS,但它似乎是一个陡峭的学习曲线,因为我不太精通 javascript 。但它似乎是一个很好的图书馆,我愿意花时间去学习它。
我想知道的是:
如何在 RaphaelJS 中使用现有的矢量图像
(如果我下载“矢量”图像,我可以告诉 RaphaelJS 绘制坐标吗?)
有没有一种方法可以将图像(jpg、gif 或其他)转换为矢量RaphaelJS 可以使用的图形。
我的困惑是,在示例页面上,图像是按照对我来说有意义的坐标绘制的。但是,如果从网上下载矢量图像,坐标在哪里?
我的目标是在我的网页上制作可点击的图像,就像 澳大利亚地图的 RaphaelJS 示例 上面有一个悬停事件。
I am starting to learn RaphaelJS, but it does seem to be a steep learning curve as I am not very versed in javascript. But it seems like such a good library that I am willing to put the time in to learning it.
What I would like to know is:
How can one use an existing vector image in RaphaelJS
(If I download a "vector" image can I tell RaphaelJS to draw the coordinates?)
Is there a way to convert an image (jpg, gif or whatever) into a vector graphic that RaphaelJS can use.
My confusion is that on the sample pages the images are drawn in coordinates which makes sense to me. However, if a download a vector image from the net, where are the coordinates?
I am aiming to make images on my web page that are clickable, much like the RaphaelJS example of the map of Australia that has a hover event on it.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
最容易读取的矢量图像格式是 svg,因为 svg 是 XML,而 XML 只是纯文本。
使用 Illustrator 或 Inkscape 等工具将矢量图像转换为 svg,然后在文本编辑器中打开它。您会发现大多数形状,例如
和
在 Raphael 中具有直接等价性。例如,
对象在其d
属性中定义路径坐标,它与 Raphael 中的路径具有相同的语法:您可以将其转换为 Raphael 的:
请注意应用于对象和组(
元素)的任何转换,您必须在 Raphael 中重复它们。举例来说,您看到以下内容:然后在 Raphael 中创建路径后,您需要应用
translate()
:您可以编写一个脚本将 svg 文件转换为 Raphael 语法或加载 svg文件在浏览器中作为文本,并使用浏览器的 XML DOM 解析器对其进行处理并使用 Raphael 进行绘制。
The easiest vector image format to read is svg since svg is XML and XML is just plain text.
Convert your vector image to svg using something like Illustrator or Inkscape and then open it in your text editor. You'll find that most of the shapes like
<path />
and<rect />
have a direct equivalence in Raphael. For example, the<path />
object defines path coordinates in itsd
attribute and it has the same syntax as paths in Raphael:You can convert that to Raphael's:
Take note though of any transformations applied to objects and groups (the
<g />
element), you'll have to repeat them in Raphael. Say for example you see the following:then after creating the path in Raphael you'll need to apply the
translate()
:You can probably write a script to convert svg files to Raphael syntax or load the svg file in the browser as text and use the browser's XML DOM parser to process it and draw it using Raphael.