[OpenLayers-Users] Formatting output text

Joel Leininger leiningr at gmail.com
Wed Aug 17 18:20:13 EDT 2011


As I understand it, js functions are standalone animals. So it doesn't
really matter where you put it, as long as you don't put it inside
another function. Put it at the end of your script if you want, just
ahead of the </script> tag.

But as I pointed out in my original post, I'm not much of a javascript
guy, so someone on the list may want to clarify (or correct) what I
said.

-J.


On Wed, 2011-08-17 at 22:10 +0000, JK Chen wrote:
> but  I don't have a mouse move function. 
> 
> 
> -----Original Message-----
> From: Joel Leininger [mailto:leiningr at gmail.com] 
> Sent: Wednesday, August 17, 2011 4:06 PM
> To: JK Chen
> Cc: Bart van den Eijnden; openlayers-users at lists.osgeo.org
> Subject: RE: [OpenLayers-Users] Formatting output text
> 
> Well, I stuck it right after the mousemove function, and it works like a charm. I actually embellished Bart's code a bit because we have some coordinate systems with South and West values. Here is my final code:
> 
> OpenLayers.LonLat.prototype.toString = function()
>     {
>     if (this.lat < 0)
>           {
>           var ns = "S";
>           this.lat = Math.abs(this.lat);
>           }
>     else {
>          var ns = "N";
>          }
>     if (this.lon < 0)
>          {
>          var ew = "W";
>          this.lon = Math.abs(this.lon);
>          }
>     else {
>          var ew = "E";
>          }
>     return (ns + "  " + this.lat.toFixed() + ", " + ew + " " + this.lon.toFixed());
>     }
> 
> (Watch the wrap in the email on the last line.)
> 
> Add number of digits desired in the toFixed(##) function.
> 
> Thanks again, Bart. The results look great.
> 
> -J.
> 
> On Wed, 2011-08-17 at 21:25 +0000, JK Chen wrote:
> >  
> > 
> > Where should the new code be inserted to?
> > 
> >  
> > 
> > Thanks.
> > 
> >  
> > 
> > JK
> > 
> > From: openlayers-users-bounces at lists.osgeo.org
> > [mailto:openlayers-users-bounces at lists.osgeo.org] On Behalf Of Bart 
> > van den Eijnden
> > Sent: Tuesday, August 16, 2011 11:28 AM
> > To: Joel Leininger
> > Cc: openlayers-users at lists.osgeo.org
> > Subject: Re: [OpenLayers-Users] Formatting output text
> > 
> > 
> >  
> > 
> > You could override the toString method of LonLat:
> > 
> >  
> > 
> > 
> > OpenLayers.LonLat.prototype.toString = function() {
> > 
> > 
> >     return ("N " + this.lat.toFixed() + ", E " + this.lon.toFixed());
> > 
> > 
> > }
> > 
> > 
> >  
> > 
> > 
> > Best regards,
> > 
> > 
> > Bart
> > 
> >  
> > 
> > --
> > Bart van den Eijnden
> > OSGIS - http://osgis.nl
> > 
> > 
> >  
> > 
> > On Aug 16, 2011, at 7:21 PM, Joel Leininger wrote:
> > 
> > 
> > 
> > 
> > How do I go about reformatting the text output from a coordinate 
> > variable?
> > 
> > In other words, I have output from a mouse position which has been 
> > transformed into different coordinate systems, and then gets displayed 
> > on the screen.
> > 
> > It now looks something like this:
> > 
> > lon=414614.58552010887,lat=164066.82345258445
> > 
> > In reality, the values are x and y coords in feet or meters, not 
> > lonlat coords. I'd like them to look like this:
> > 
> > N 164066, E 414614
> > 
> > Note the truncation of the digits and switching of the x, y (which is 
> > customary in my field). Not being a JS expert, I can't figure out how 
> > to get at the variable to massage the format prior to display on the 
> > screen.
> > 
> > Here's the code leading up to the display (inside of a mousemove
> > function):
> > 
> > mousepos = map.getLonLatFromViewPortPx(e);
> > var NAD83ft_values = mousepos.clone();   // done several times for
> > different coord translations
> > 
> > NAD83ft_values.transform(WGS84_google_mercator, NAD83ft_proj); 
> > document.getElementById("NAD83feet").innerHTML = NAD83ft_values;
> > 
> > 
> > It's unpacking NAD83ft_values that has me thrown. Any help?
> > 
> > -J.
> > 
> > 
> > 
> > _______________________________________________
> > Users mailing list
> > Users at lists.osgeo.org
> > http://lists.osgeo.org/mailman/listinfo/openlayers-users
> > 
> > 
> >  
> > 
> > 
> 
> 




More information about the Users mailing list