[Mapserver-users] How to get X and Y pixel coordinates with JavaScript

Merlos merlos at tsc.uvigo.es
Wed Jul 21 07:50:34 EDT 2004


On Wednesday 21 July 2004 10:29, you wrote:
> First of all, you'll probably encounter difficulties to have
> cross-browser compatibility with such a simple javascript.

Yes, and I suppose whitch company is the responsible of this fault of 
following standards.

> You may want to use a cross-browser library. As Steve Lime uses CBE for
> his DHTML Landview interface, I prefered the new X library (its
> substitute). Find it at http://www.cross-browser.com.
> An other choice could be the DynAPI library.
> Well this is for browser compatibility.
>
> Then the aim is to use "event handlers" on a target DIV to get the mouse
> coordinates.
>
> See the simple exemple below.
>
> Regards

My biggest problem is that one of the target platforms is Pocket PC, witch 
does not have layer support. Precisely is in this platform where my interests 
were centered because the refreshing times become appreciable. On the PCs I 
haven't this problem. I suppose this is because they can detect the changes 
on the html and refresh only that changes or because the system speed is fast 
enougth.

I was searching something as much simple as possible, because my javascript 
skills are not as good as I would like and because of the limitations of the 
Pocket PC platform.

The browser does not set the X and Y coordinates on the JS object  before the 
submission? 



Thank you for your time Pierre!

> Pierre GIRAUD
> camptocamp.com
>
> ps : if you want to see a working exemple of DHTML interface, follow
> this link http://sitn.ne.ch.
> Note that it doesn't answer to your needs because the page is reloaded
> each time the user navigates. Steve Lime's work does.
>
> ------- to use this, you'll need to download the required X library's
> files in a "js" folder --------------------------------
>
> <html>
> <head>
> <title> [Mouse Events]</title>
> <script type='text/javascript' src='js/x_core_nn4.js'></script>
> <script type='text/javascript' src='js/x_event_nn4.js'></script>
> <script language="JavaScript">
> onload = init
> function init() {
>     mylayer = xGetElementById("mylayerDiv")
>     xAddEventListener(mylayer,'mousedown',layerDownHandler)
>     xAddEventListener(mylayer,'mouseup',layerUpHandler)
> }
>
> function layerDownHandler(evt) {
>     var e = new xEvent(evt)
>     var x = e.offsetX
>     var y = e.offsetY
>     document.myform.downx.value = x
>     document.myform.downy.value = y
>     return false
> }
>
> function layerUpHandler(evt) {
>     var e = new xEvent(evt)
>     var x = e.offsetX
>     var y = e.offsetY
>     document.myform.upx.value = x
>     document.myform.upy.value = y
>     return false
> }
> </script>
> <style text="text/css">
> <!--
> #mylayerDiv {position:absolute; left:150; top:80; width:300; height:200;
> clip:rect(0,300,200,0); background-color:#C0C0C0;
> layer-background-color:#C0C0C0;}
> -->
> </style>
> </head>
>
> <body bgcolor="#ffffff">
>
> <b>Layer-based mouse events</b>
>
> <form name="myform">
>
> down X: <input type="text" name="downx" size=3>
> <br>down Y: <input type="text" name="downy" size=3>
>
> <p>up X: <input type="text" name="upx" size=3>
> <br>up Y: <input type="text" name="upy" size=3>
>
> </form>
>
> <div id="mylayerDiv">
> </div>
>
> </body>
> </html>
>
> -------------------------------------------------------------------------
>
> 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
>
> _______________________________________________
> Mapserver-users mailing list
> Mapserver-users at lists.gis.umn.edu
> http://lists.gis.umn.edu/mailman/listinfo/mapserver-users



More information about the mapserver-users mailing list