如何在拉斐尔“纸”上添加标记在 JavaScript 中?
我需要一个行为类似于向地图添加标记的标记。双击时,会在单击的点处显示标记,并返回单击的点的 x/y 像素坐标。
我有拉斐尔纸:
var R = Raphael("paper", 500, 500);
上面有路径 (R.path("M 92.3456 ... 37.0934 Z")
) 定义形状。我必须在这张纸上添加带有形状的标记。
我不是一个 javascript 程序员,所以我什至不知道从哪里开始。因此,非常感谢这里的任何帮助!
I need a marker that behaves much like adding a marker to a map. On double click cause a marker to be displayed at the point that was clicked, and returns the x/y pixel coordinates of the point that was clicked.
I have Raphael paper:
var R = Raphael("paper", 500, 500);
with paths (R.path("M 92.3456 ... 37.0934 Z")
) on it that defines shapes. And I have to be albe to add markers on this paper with shapes.
I am not a javascript programmer so I don't really even know where to start. So any help here is much appreciated!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好吧,我做了这个简单的小提琴来帮助你解决你的问题。
http://jsfiddle.net/mN5du/1/
我只是向圆圈添加了 Raphael 双击事件(你可以对你的路径做同样的事情)。当此事件被触发时,将鼠标坐标存储在两个变量中。然后我用这两个变量来画一个新的圆。如果你想画一条路径而不是一个圆,你只需要使用路径坐标中的变量。
我希望这对你有用!如果您有任何疑问,请告诉我!再见!
编辑:看看下面的评论,是对答案的很好贡献!
Edit2:行
console.log(x,y)
用于在浏览器控制台中打印鼠标值,代码不需要工作。Ok, I've made this simple fiddle to help you with your problem.
http://jsfiddle.net/mN5du/1/
I just add a Raphael doubleclick event to the circle (you can do the same with your paths). When this event is fired up, stores the mouse coordinates in two variables. Then I just use those two variables to draw a new circle. If you want to draw a path instead of a circle, you just need to use the variables within the path coordinates.
I hope this works for you! If you have any questions just tell me! bye!
Edit: Look at the commentary Below, is a good contribution to the answer!
Edit2: The line
console.log(x,y)
Its there to print the mouse values in the browser console, it's not necessary for the code to work.