scale?

Larry Shaffer larry at SHAFFERINTERACTIVE.COM
Mon Jan 30 13:20:25 EST 2006


Luis, thanks for the Javascript! I was going to need a similar piece of
code for an upcoming project.


Jeremy, when Luis's code mentions...

>   var mytext=document.createTextNode(escalaStr)
>
>   document.getElementById("MyElementID").appendChild(mytext)

it is appending a test node to an HTML element (essentially adding text
content) with the id="MyElementID" and that element needs to already
exist in your template somewhere (it can be a variety of elements, empty
or not, that will work).

When Luis's code reads...

>  <body onload="TomaEscala([scale]);">

it just calls the javascript to do the transformation of the [scale]
value supplied by the Mapserver CGI. Javascript will not substitute the
old [scale] with the new scale created unless the [scale] value is
contained by the element of id="MyElementID". But, you don't need it to
do that. The script will output the new scale, as text, directly to an
empty HTML element of your choosing.

The only thing I have noticed, and I haven't had time to actually test
the script, is that there is no accounting for a browser that does not
support the 'createTextNode' method (or the appendChild method). The
'innerHTML' method may work for some quirky browsers, but is not W3C DOM
compliant, and not recommended. Setting the value of a form element,
though, to the created scale value should work in almost all browsers.
But, then, your scale would have to be in a form element, which is not so
easy to work with for display purposes.

In other words, Luis's script may not work on older, non-DOM compliant,
browsers, without some additional coding to accommodate them.
Accommodating quirky, older browsers is the bane of including javascript.

-- 
Larry Shaffer
Black Hills of South Dakota 
USA (Mountain Time Zone)


# Sears, Jeremy <Jeremy.Sears at CCRS.NRCAN.GC.CA> emailed the following
#   on Mon, Jan 30, 2006 at 12:03 PM (10:03 AM South Dakota, USA):

>Map Scale: &nbsp &nbsp &nbsp 1:[scale]
>
></td>
>
> 
>
>However the output of this code doesnt is as follows:
>
>Map Scale:    1:[scale]
>
> 
>
>It would seem that the scale value isnt being subsituted. Can you suggest
>what might (or might not) be causing this?
>
>Gracias
>
>Jeremy
>
> 
>
> 
>
>-----Original Message-----
>From: Luis Treviño Huerta [mailto:ltrevino at gpobsi.com.mx]
>Sent: January 30, 2006 11:51 AM
>To: Sears, Jeremy; MAPSERVER-USERS at LISTS.UMN.EDU
>Subject: Re: [UMN_MAPSERVER-USERS] scale?
>
>
>Jeremy:
> 
>The substitution of the [scale] value is done by mapserver CGI.
>this is the javascript function:
>function TomaEscala(scale){
>
>var escala, escalaStr, decimal;
>
>
>
>escala = scale; 
>
>escala *= 100; 
>
>escala = Math.round(escala); 
>
>escala /= 100; 
>
>escalaStr = Math.abs(escala).toString(); 
>
>
>
>entero = escalaStr.substr (0,escalaStr.length-3);
>
>if (entero.length > 3) {
>
>    longitud = entero.length % 3;
>
>    while (longitud < entero.length) {
>
>    if (longitud == 0) {
>
>        longitud = 3;
>
>    }
>
>    entero = entero.substr (0,longitud) + "," +
>entero.substr(longitud,entero.length);
>
>    longitud += 4;
>
>    }
>
> }
>
>  escalaStr = entero;
>
>   if (document.createTextNode){
>
>   var mytext=document.createTextNode(escalaStr)
>
>   document.getElementById("MyElementID").appendChild(mytext)



More information about the mapserver-users mailing list