DMS display on MouseMove
Puneet Kishor
punkish at EIDESIS.ORG
Thu Feb 9 08:33:46 PST 2006
william paul wrote:
> Well, As i sad before:
>
> I am not having problems with theory about projections (I have some
> experience in cartography...and I understand what is a projection), I am
> having problems with CODING, here I am NEW. I just wanted to see some
> examples, but I will find the solution
>
And, I am trying to help you with that. Let's take it again step by step:
1. for any given view, you know the dims of that map in pixels as well
as in your coords, in this case, lat/long (that they are expressed in DD
or DMS doesn't matter for now).
2. given the above, you can figure out how much real world distance each
pixel represents by dividing the max world coords in each direction (x
and y) by the respective pixel width and height.
3. since you know the current position of your mouse in pixels, you can
figure out the current displacement of your mouse in real world coords
relative to the 0,0 on your map image using the values from #1 and #2 above.
4. since you know the min coords of the real world that your map image
covers, adding the values from #3 above to these min coords will give
you the real world coords of your mouse.
one caveat -- real world coords have 0,0 in the lower left corner of the
view, while the image in a browser has 0,0 in the upper left corner of
the view. You will have to flip the y coords accordingly.
If you follow the above logic, and follow your DD code, you will
understand it and everything will be clear.
Once you get the above under your belt, showing lat/long in DD vs. DMS
is just a matter of units. That conversion you already know.
Another hint -- download the code from just about any MapServer example,
and you will find the above code in there somewhere. For starters, look
at Steve Lime's basic examples. They are great for learning.
Good luck.
>
>
> */Puneet Kishor <punkish at eidesis.org>/* wrote:
>
>
> On Feb 9, 2006, at 7:57 AM, william paul wrote:
>
> > I replay to the email, I didn't thing that the list will not receive
> > the email!!!
> >
> > My problem isn't how you transform from DD to DMS. I already know
> this.
> >
> > I want to make the transformation in such manner that the DMS are
> > displayed ON MOUSEMOVE over the map, which means that the
> coordinates
> > are changing with position of the cursor on the map
> >
> > I did that for DD using a script found on the list, but I can't make
> > it work for DMS
> >
> > My code looks like:
> >
> > var x2 = event.offsetX; // mouse coordinates in pixels
> > var y2 = event.offsetY; // mouse coordinates in pixels
> > var res_dd = ([maxlon] - [minlon]) / [mapwidth]; // resolution in DD
> > var x_dd = [minlon];
> > var y_dd = [minlat];
> > x1_dd = Math.round(((x2*res_dd) + x_dd)*1000000)/1000000;
> > //coordinates in DD to be displayed on mousemove
> > y1_dd = Math.round(((([mapheight] - y2)*res_dd) +
> > y_dd)*1000000)/1000000; //coordinates in DD to be displayed on
> > mousemove
> >
> > window.status="Latitude DD: " + y1_dd + " " + "Longitude DD: " +
> y1_dd;
> >
> > I tried for DMS:
> >
> > //for longitude in DMS
> >
> > var dd = Math.floor(x1_dd);
> > var m = Math.floor((x1_dd - dd) * 60);
> > var s = Math.ceil((((x1_dd - dd) * 60) - m) *60);
> >
> > I also have tried to break the resolution in DMS, but I don't
> know how
> > to multiply the resolution with the coordinates in pixel and then
> add
> > to minlon
>
>
> I am not sure what the problem is. Do for DMS exactly the way you are
> doing for DD. There is nothing conceptually different between DD and
> DMS. They express the same thing in different ways -- it is like saying
> 1 lb of tomatoes versus 454 gms of tomatoes. Figure out your min, max
> in DMS, and add them to your current mouse coordinates.
>
> That said, look at Clint Johnson's email from yesterday. He recommends
> reading about projections at
> http://fisher.lib.virginia.edu/reference/help/esri/esri_pdfs_9.html,
> and that should be the first thing that all MapServer users should read
> before setting out making mapping websites. Ed McNierny also has
> elaborated on this several times (in fact, I have been thinking of
> taking all of Ed's emails and compiling them into a "must read"... note
> to Ed -- if you save your MapServer-list emails, forward them to me and
> I will do the rest).
>
> Remember, that the pixel space is a rectangle, in that, opposite sides
> are equal, while Lat/Long space is more like a trapezoid, in that, the
> horizontal opposite sides are not equal, and in fact, at the poles, it
> becomes a triangle. If you really want to be exact with your coordinate
> display, project your map into a rectangular coordinate system and then
> you will get what you want.
>
>
> >
> > william paul wrote:
> > > Hi:
> > >
> > > I know this, my problem is other, but...I will solve it
> >
> > Please send all replies to the list as well. In the meantime, would
> > the following help --
> >
> > //(0) Grab the dd value
> > var dd = obj.value;
> >
> > // (1) The Degrees are simply the numbers to the left of the decimal
> > // (using 42.36824 as an example, the degrees would be 42)
> > var d = Math.floor(dd);
> >
> > // (2) To determine the Minutes, multiply the number to the right of
> > // the decimal point by 60 (example: .36824 x 60 = 22.0944)
> > // (3) The Minutes are the numbers to the left of the decimal point
> > // (in this example, 22)
> > var m = Math.floor((dd - d) * 60);
> >
> > // (4) To determine the Seconds, multiply the number to the right of
> > // the decimal point by 60 (example: .0944 x 60 = 5.664)
> > // (5) The Seconds are the numbers to the left of the decimal point,
> > // rounded up (in this example, 06)
> > var s = Math.ceil((((dd - d) * 60) - m) * 60);
> >
> > // display it
> > var dms = d + ' deg, ' + m + ' min, ' + s + ' sec';
> >
> > >
> > > */Puneet Kishor /* wrote:
> > >
> > > william paul wrote:
> > > > Hi:
> > > >
> > > > I display the coordinates on mousemove over the map. The
> > > coordinates are
> > > > in DD and UTM, but I would like display them also in DMS.
> > > >
> > >
> > > From the very first hit on Google --
> > >
> > > (1) The Degrees are simply the numbers to the left of the
> decimal
> > > (using 42.36824 as an example, the degrees would be 42)
> > > (2) To determine the Minutes, multiply the number to the right
> > of
> > > the decimal point by 60 (example: .36824 x 60 = 22.0944)
> > > (3) The Minutes are the numbers to the left of the decimal
> point
> > > (in this example, 22)
> > > (4) To determine the Seconds, multiply the number to the
> right of
> > > the decimal point by 60 (example: .0944 x 60 = 5.664)
> > > (5) The Seconds are the numbers to the left of the decimal
> point,
> > > rounded up (in this example, 06)
> > >
> > > Implementing it in Js is left as an exercise for the reader...
> > >
> > >
> >
> >
> > --
> > Puneet Kishor
More information about the MapServer-users
mailing list