如何在拉斐尔“纸”上添加标记在 JavaScript 中?

发布于 2024-12-22 20:05:11 字数 286 浏览 2 评论 0原文

我需要一个行为类似于向地图添加标记的标记。双击时,会在单击的点处显示标记,并返回单击的点的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

女皇必胜 2024-12-29 20:05:11

好吧,我做了这个简单的小提琴来帮助你解决你的问题。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文