473,782 Members | 2,479 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

selection rectangle

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="javas cript">
<!--
function twPositionRelat ive(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.getEl ementById) {
nOffsetX = evt.pageX - document.getEle mentById("monIm age").offsetLef t;
nOffsetY = evt.pageY - document.getEle mentById("monIm age").offsetTop ;
}
document.getEle mentById("hTrac e").innerHTM L = "X : "+nOffsetX+ " ; Y :
"+nOffsetY;
}
}

function twInit() {
var oImage = document.getEle mentById("monIm age")
if (oImage) {
oImage.style.cu rsor = "crosshair"
oImage.onmousem ove = twPositionRelat ive
}
}
-->
</script>

Apr 22 '06 #1
11 6766
ASM
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
Apr 22 '06 #2
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.

Apr 22 '06 #3
ASM
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
Apr 22 '06 #4
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 :D 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=coordonne e" 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.

Apr 22 '06 #5
thom wrotes :
im not so used with javascript, and have no clue
on how to save the "name=coordonne e" 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\">al ert(\"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\">po ints;</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.


Apr 23 '06 #6
ASM
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
Apr 23 '06 #7
ASM
thom a écrit :
thom wrotes :
im not so used with javascript, and have no clue
on how to save the "name=coordonne e" 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="'"+pos1 x+"','"+pos1y+" ','"+posx+"','" +posy+'";
or :
points="'"+pos1 x+"','"+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
Apr 23 '06 #8
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 :D
Sorry 2 : I'm on holiday this evening (10 days)


you lucky!
've nice holidays ;)

thom.

Apr 26 '06 #9
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.

May 8 '06 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
4028
by: Philippe Meunier | last post by:
Hi, I would like to know How I could draw a Dashed rectangle over everything in a container. I will use this to draw a selection rectangle (like in VB.NET Form Designer UI). And even it draws in invert colors I think, but this is not necessary for now. Can I do this with a usercontrol ? Because I know that transparency is a little tricky in VB.NET, for usercontrols.
5
3318
by: (Pete Cresswell) | last post by:
I've got a TreeView on the left of my screen. As the user navigates the tree, I load corresonding detail info into the rest of the screen. Works ok, but when the user clicks on a detail field, the TreeView's selection rectangle goes away and the user is left wondering what happened. Seems like there ought TB a way to preserve that rectangle. The optimal would be to have it go grey when the control loses focus and return to blue whe...
2
6809
by: (Pete Cresswell) | last post by:
Seems like I've been here before, but can't find anyting in Google. I've got two list boxes on a form. Seems to me like the inactive ListBox's selection rectangle should be something like gray...otherwise, the user sees two ListBoxes, both with black selection rectangles - and the user does not visually know which one he is "in". This becomes relevant if we have a keyboard-type user - they want to hit "Enter" and have something...
3
2911
by: Jeroen Ceuppens | last post by:
I need a selection tracker on a graphic Idea: left click: rectangle appear en grows when you move the mouse, again clicking is lock te rectangle How do you do that? Greetz Jeroen
3
3652
by: TT (Tom Tempelaere) | last post by:
Hi there, In my application I have a panel that contains a matrix of user controls. The user control is fairly simple. It merely draws a circle that represents an object in my code. The object has certain properties that can be configured, so each control has a context menu that allows such operations. However, my application requires setting properties for multiple objects at once. That would require being able to select multiple...
10
2063
by: Tyrant Mikey | last post by:
I don't know if this can even be done, but I'd REALLY like to eliminate the selection rectangle that appears around my ImageButton controls when the user clicks on them. The buttons are on a black background, and the selection rectangle looks like complete crap. Any suggestions are greatly appreciated!! Thanks!
0
1383
by: Brian Henry | last post by:
I am trying to do a owner drawn list view in detail mode, when i inherited the list view into a new custom control then turned on double buffering all the sudden the selection rectangle is the alpha channel transparent one that windows xp's shell uses... is there any way to just keep the standard dotted rectangle one? because performance is slow when the transparent rectangle region is enabled with double buffering... but i cant find a way...
0
1423
by: (PeteCresswell) | last post by:
Got a TreeView control on the screen. User clicks a node, screen loads details for that node. Screen has two modes: Browse and Edit. If the user clicks "Edit", I set Tree.Enabled=False and make the detail fields on the screen editable. Tree.Enabled=False because once the screen is in "Edit" mode for data behind a
5
12670
by: Jure Bogataj | last post by:
Hi all! I have a problem (performance issue) with listview. I have implemented an ItemSelectionChange on my listview and put some code in it (I build some toolbar based on selection and update info in statusbar). When selecting one item (clicking on listview) it works fast, without noticing. However if selecting multiple items with SHIFT (approx. 500 items) or selecting with mouse, for each item selected through all listview an event...
0
9641
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10313
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10080
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
6735
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5378
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5511
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4044
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3643
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2875
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.