[Mapserver-users] How to get X and Y pixel coordinates with JavaScript
Paul Spencer
pspencer at dmsolutions.ca
Wed Jul 21 06:07:57 PDT 2004
Hi,
There are several options for handling this.
First, don't use a form element, use an img tag and use
onmouseover/out/move events and track mouse location that way.
In IE, you can also attach to onmousedown/onmouseup on an img element.
In Netscape, you can only attach onmouseup/down at the document level.
Here is the logic that I have used to do something like this (note this
is completely untested and likely contains typos etc):
<img src="" onmouseover="myCaptureMouse()" onmouseout="myReleaseMouse()">
<script>
var mouseX, mouseY, oldMouseUp, oldMouseMove;
function myCaptureMouse()
{
oldMouseUp = document.onmouseup;
oldMouseMove = document.onmousemove;
document.onmouseup = myMouseUp;
document.onmousemove = myMouseMove;
}
function myReleaseMouse()
{
document.onmouseup = oldMouseUp;
document.onmousemove = oldMouseMove;
}
function myMouseMove( e )
{
if (isIE) e = window.event;
mouseX = e.X;
mouseY = e.Y;
}
function myMouseUp( )
{
alert( 'click at ' + mouseX + ':' + mouseY );
}
</script>
Merlos wrote:
> Hello,
>
> Maybe someone can help me. I was wondering if when an user clicks on the
> image that is on an <input type="image"> element it is possible to capture
> the X and Y coordinates before the submission is done. I mean:
>
> <script type="text/javascript">
>
> function formSubmit() {
> //Here get the X and Y coords in pixels... Is it possible? How?
> }
> <form name="apatruyando" action="JavaScript:formSubmit()">
> <input type="image" src="image_url.png" />
> </form>
>
> The idea is to change with the JS the image src atribute of the input type
> each time the user clicks on, that way it wouldn't be necessary to refresh
> all the page.
>
>
> Thank you.
> _______________________________________________
> Mapserver-users mailing list
> Mapserver-users at lists.gis.umn.edu
> http://lists.gis.umn.edu/mailman/listinfo/mapserver-users
>
--
-----------------------------------------------------------------
|Paul Spencer pspencer at dmsolutions.ca |
|-----------------------------------------------------------------|
|Applications & Software Development |
|DM Solutions Group Inc http://www.dmsolutions.ca/|
-----------------------------------------------------------------
More information about the MapServer-users
mailing list