mouse click with jBox

Steve Lime Steve.Lime at DNR.STATE.MN.US
Wed Jun 28 02:31:26 EDT 2006


Jbox doesn't operate in map coordinates. It's rather stupid and only knows about pixels. I believe there is a callback function called something like setbox that returns the minx, miny, maxx, maxy of the last mouse up event. In the case of a box draw you'll get 4 seperate values, if just a point click then minx=maxx and miny=maxy.

In any event, you can get the click (in pixels) in that callback function. You'll have to turn the click into map coordinates yourself.

How you do that depends on the implementation. Typically though you'll know the extent of the image and the size. From there you can compute a cellsize (maxx - minx)/(width-1), and then converting to pixels is easy:

  mx = minx + cellsize*px;
  my = maxy - cellsize*py;

Where mx, my are the map coordinates, minx, miny, etc... are the map extent of the map and px, py are the pixel coordinates.

Steve

>>> Luis Treviño Huerta <ltrevino at GPOBSI.COM.MX> 06/27/06 5:45 PM >>>
Hi list,

I'd like to save in a javascript variable, the position (lat/lon) when the 
user clicks over the map,
Does anybody know how can I get the mouse click position using jBox?

Regards,
Luis 



More information about the mapserver-users mailing list