How do I get the x and y coordinate in javascript in PlotPanel
John Val
13 Posts
Dear all,
I would like to start a simulation from a point under a mouseclick in the plotpanel in the javascript version. In the plotting panel of the FunctionPlotter example I enabled interaction and put %mouseClick% at the Onpress event.
In this functioen I would like to read the x and y postion under the cursor. I know I must be able to get them somewhere since in the lower left corner a box with these values appears.
function mouseClick() { var x= _view.plottingPanel.pointer.x; // this does not work. But what does? alert(x); }
Re: How do I get the x and y coordinate in javascript in PlotPanel -
Francisco Esquembre
237 Posts
Hi John,
1.- Add a parameter to the mouseClick function. As "point" in my example below. EjS will provide a double[2] array with the coordinates of the clicked point.
function mouseClick (point) { console.log ("Clicked at "+point); }
2.- specify %mouseClick% at the OnPress event as you did.
3.- Make sure the panel is Enabled.
So, the trick was specifying (and using) a parameter in the mouseClick function.