Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > selection rectangle

Reply
Thread Tools

selection rectangle

 
 
thom
Guest
Posts: n/a
 
      04-22-2006
Hello everybody,

Here is a little javascript that gives me the mouse's
x and y coordinates.

Now, i'd like to be able to make selection(s) rectangle(s)
on a given image with it.
And then, save the selection's specs.

For what i've seen by now: the major problem is the DOM compliant,
and browsers compatibility.

Could you please help/point me out doing it?

thanks in advance,
Thom.

//-------------------------
//The Code:
//-------------------------
<script type="text/javascript" language="javascript">
<!--
function twPositionRelative(evt) {
var nOffsetX;
var nOffsetY;
evt = (evt) ? evt : ((window.event) ? window.event : "");
if (evt) {
if (document.all) {
nOffsetX = evt.offsetX;
nOffsetY = evt.offsetY;
}
else if (document.getElementById) {
nOffsetX = evt.pageX - document.getElementById("monImage").offsetLeft;
nOffsetY = evt.pageY - document.getElementById("monImage").offsetTop;
}
document.getElementById("hTrace").innerHTML = "X : "+nOffsetX+" ; Y :
"+nOffsetY;
}
}

function twInit() {
var oImage = document.getElementById("monImage")
if (oImage) {
oImage.style.cursor = "crosshair"
oImage.onmousemove = twPositionRelative
}
}
-->
</script>

 
Reply With Quote
 
 
 
 
ASM
Guest
Posts: n/a
 
      04-22-2006
thom a écrit :
> Hello everybody,
>
> Here is a little javascript that gives me the mouse's
> x and y coordinates.


have a look here :
http://perso.wanadoo.fr/stephane.mor...oord_carte.htm
to see how I propose to catch coordinates on an image

Preferably to do not use detection with document.all
because not only IE understand that

To get your selection, easiest way would be to use two successive clicks
1st angle, then oposite angle.

as I do here :
http://perso.wanadoo.fr/stephane.moriaux/truc/suisse/
(caution : not finished don't click on green button)
(page in french, and wide screen needed)

You may too use a combination of keys to simulate the lasso ?

You could go here :
http://www.walterzorn.com/dragdrop/dragdrop_e.htm
to see if there is something interresting about your deal.


--
Stephane Moriaux et son [moins] vieux Mac
 
Reply With Quote
 
 
 
 
thom
Guest
Posts: n/a
 
      04-22-2006
First merci beaucoup answering me so fast and so right!
the given links are the kind of things i'm wishing to do.
(http://perso.wanadoo.fr/stephane.moriaux/truc/suisse/)

i'm gonna try to let user make multiple selections
on the picture, then generate the corresponding map.


ASM wrote :

> Preferably to do not use detection with document.all
> because not only IE understand that

you're right, a similar script (based on the given one in my
first post) doesn't work properly in all browsers when
adding the selection rectangle funcs (especially Mac's safari
if i remember right).


Thom.

 
Reply With Quote
 
ASM
Guest
Posts: n/a
 
      04-22-2006
thom a écrit :
> First merci beaucoup answering me so fast and so right!
> the given links are the kind of things i'm wishing to do.
> (http://perso.wanadoo.fr/stephane.moriaux/truc/suisse/)
>
> i'm gonna try to let user make multiple selections
> on the picture, then generate the corresponding map.


This example was basically to get several areas cooordinates
and was a little simplified to one area (in order to go to a new page
with this area taller re-sized (suite en devenir ...) )

Instead to begin a new fresh selection you just need :
- to validate the onwork selection
- to begin a new one while keeping the old one.

Validations could be stocked in an array.

> a similar script (based on the given one in my
> first post) doesn't work properly in all browsers when
> adding the selection rectangle funcs (especially Mac's safari
> if i remember right).


if it works on 1st point it would have to work with 2nd point.

I would do something like that :
- image to map
- a hidden div with border and transparent background-image
with a onclick function to select this div
- a lasso function similar that I have on given example
on 1st click : 1st point and stock in a variable
on 2nd click or double-click : 2nd point stocked
then :
- cloning hidden div above
- giving it correct size and place (from stock)
- giving it an id and visibility
- eventualy to give it a title or/and a link in accordance
- perhaps to stock all necessary in an array
- when clicking on this new div : function to re-arrange it ?
- a button to validate the complete map
to create html code of all this clones
(using a loop on collection of this clones
with result in a textarea to afterward copy its content)

--
Stephane Moriaux et son [moins] vieux Mac
 
Reply With Quote
 
thom
Guest
Posts: n/a
 
      04-22-2006
Hello,

my comments will be based on your code (suisse),
so you can better understand what i'm talking about,
and you know what you've done, i don't and
my try-outs are not fully working for the moment.

ASM wrote :

> Instead to begin a new fresh selection you just need :
> - to validate the onwork selection
> - to begin a new one while keeping the old one.
>
> Validations could be stocked in an array.


that's would be done in the termine() function ?

> Validations could be stocked in an array.


im not so used with javascript, and have no clue
on how to save the "name=coordonnee" values
(the one you have used in the input form to show the points)
into a php array,in order to generate the map coordinates using
this array values.

> - to validate the onwork selection
> - to begin a new one while keeping the old one.


so keeping the selection is to save values in the array
and still showing up the selected rectangle(s) while making
another one.
Meaning if user has made 3 selections, at end, you
will see the 3 rectangle on your suisse map.
None of them being cleared with the raz() function or the termine().

how?

> I would do something like that :
> - image to map
> - a hidden div with border and transparent background-image
> with a onclick function to select this div
> - a lasso function similar that I have on given example
> on 1st click : 1st point and stock in a variable
> on 2nd click or double-click : 2nd point stocked
> then :
> - cloning hidden div above
> - giving it correct size and place (from stock)
> - giving it an id and visibility
> - eventualy to give it a title or/and a link in accordance
> - perhaps to stock all necessary in an array
> - when clicking on this new div : function to re-arrange it ?
> - a button to validate the complete map
> to create html code of all this clones
> (using a loop on collection of this clones
> with result in a textarea to afterward copy its content)
>

Wow O_o! amazing, sounds very good, but i don't think
i could make it work lol! That's my feeling for moment,
but who knows, someday maybe

Thanks for helping,
thom.

 
Reply With Quote
 
thom
Guest
Posts: n/a
 
      04-23-2006
thom wrotes :

> im not so used with javascript, and have no clue
> on how to save the "name=coordonnee" values
> (the one you have used in the input form to show the points)
> into a php array,in order to generate the map coordinates using
> this array values.
>

in terminee() i modified a var which i gave the coordianates, like
this: points=" "+pos1x+" "+pos1y+" "+posx+" "+posy+" ";
then i wanted to take the value from points into php.

Is i possible using something like this?

<?php
echo "<script type=\"text/javascript\">alert(\"value from points var:
\"+points);</script>";
?>

instead of the popup, maybe i could affect the point value to a
php var like:

<?php
$coords = echo "<script type=\"text/javascript\">points;</script>";
?>


OK then i understood you were using C.value to do what i told
you with my variable
So the C.value would be used instead of my var points.


thom.




 
Reply With Quote
 
ASM
Guest
Posts: n/a
 
      04-23-2006
thom a écrit :
> thom wrotes :


[...]

> OK then i understood you were using C.value to do what i told
> you with my variable
> So the C.value would be used instead of my var points.


hi thom,

you'll find something more finished here
http://stephane.moriaux.perso.wanado...uisse/thom.htm

when all areas are fixed the push on green button
catch all areas and create html code (links width sizes and position)
all this html code comes in a textarea of a form

you'll put your php file url in this form's action
to get this area value

Sorry it was too difficult to explain step by step what you could do
with precedent example.

Sorry 2 : I'm on holiday this evening (10 days)

--
Stephane Moriaux et son [moins] vieux Mac
 
Reply With Quote
 
ASM
Guest
Posts: n/a
 
      04-23-2006
thom a écrit :
> thom wrotes :
>
>> im not so used with javascript, and have no clue
>> on how to save the "name=coordonnee" values
>> (the one you have used in the input form to show the points)
>> into a php array,in order to generate the map coordinates using
>> this array values.
>>

> in terminee() i modified a var which i gave the coordianates, like
> this: points=" "+pos1x+" "+pos1y+" "+posx+" "+posy+" ";
> then i wanted to take the value from points into php.


preferably :
points="'"+pos1x+"','"+pos1y+"','"+posx+"','"+posy +'";
or :
points="'"+pos1x+"','"+pos1y+"';'"+posx+"','"+posy +"'";

Like that the text field C value will be an array
or an array of 2 arraies

> Is i possible using something like this?


you confuse me with your php I sniped

on example all work by JavaScript

positions of 2 oposit points of selection are in the text field

all what you have to do is to put the right uri of your php file in the
action of this form to get this text field value
when you submit with green button

> OK then i understood you were using C.value to do what i told
> you with my variable
> So the C.value would be used instead of my var points.


if C is the text field of form, I think yes


--
Stephane Moriaux et son [moins] vieux Mac
 
Reply With Quote
 
thom
Guest
Posts: n/a
 
      04-26-2006
Hi stephane,

ASM wrote :

> you'll find something more finished here


> Sorry it was too difficult to explain step by step what you could do
> with precedent example.
>


Don't worry for that, it's very kind of you having posted a new
source code for me... it's now time for me to study it

> Sorry 2 : I'm on holiday this evening (10 days)
>


you lucky!
've nice holidays

thom.

 
Reply With Quote
 
thom
Guest
Posts: n/a
 
      05-08-2006
Hello,
i hope u'll read this post today:
your code is running like a charm if on a single page,
but once you put it into a div, which you selected the style position,
the selection rectangle are not on the picture anymore, say i click one
point, the showing point is 100px left etc.. (doesn't match anymore).
I know it is css, but wow, can't find a solution!
Did you? or someone else?

thx, thom.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Q: How to eliminate selection rectangle on ImageButton? Tyrant Mikey ASP .Net 10 02-07-2005 06:26 PM
JTable with row selection, but no cell selection Simon Niederberger Java 2 01-07-2005 04:17 PM
JS comparing innerHTML to text selection (window.getSelection() /document.selection) Andrew Crowe HTML 1 09-13-2004 02:22 PM
How to change a range selection to text selection? Loebb Javascript 0 02-23-2004 02:12 PM
HOWTO autopost the selection list upon selection curiousity ASP .Net Mobile 0 11-21-2003 12:57 AM



Advertisments