[Mapserver-users] Re: select mapsize from combo box

Zatorsky.MichaelP at police.qld.gov.au Zatorsky.MichaelP at police.qld.gov.au
Wed Feb 12 21:18:15 EST 2003


One simple way of maintaining persistence of the map size from one HTML page to the next is to use the [mapsize]variable in your HTML code. As an example:

        <b>Map Size:</b><br>
        <select name="mapsize">
            <option value="[mapsize]">[mapsize]</option>
            <option value="300 200"> 300 200</option>
            <option value="640 480"> 640 480</option>
            <option value="800 600"> 800 600</option>
            <option value="1024 768">1024 768</option>
        </select>

The map size selected for the next map automatically defaults to the size of the current map (as its listed first in the select options).  There are more elegant JScript solutions, but this works well.

Regards
Michael.

Michael Zatorsky
Manager, Geographic Information Services
Queensland Police Service
GPO Box 1440, Brisbane, QLD 4001, AUSTRALIA
p. 07 3364 4384             f. 07 3364 3942
e. zatorsky.michaelp at police.qld.gov.au 




-----Original Message-----
From: Richard Greenwood [mailto:rich at greenwoodmap.com]
Sent: Monday, 10 February 2003 11:49 PM
To: Steve McCrone
Cc: mapserver-users at lists.gis.umn.edu
Subject: [Mapserver-users] Re: select mapsize from combo box


At 09:05 PM 2/10/2003 +0800, you wrote:

>Hi Richard,
>
>The reason I'm contacting you is due to the fact that you have a combo box
>on your site where the user can select to change the map size. I too am
>trying to implement that. It looks easy but I've got a problem I was
>wonfering if you could help me with (I'v also posted this to the user
>group).
>
>I am trying to duplicate the change in mapsize as seen in the GMap sample of
>the map of Canada.
>Here's what I've got so far -
>
><SELECT name=MapSize onchange=MapSizeSelected()>
><OPTION value="550 500">550 x 500</OPTION>
><OPTION value="600 500">600 x 500</OPTION>
></SELECT>
>
>and
>
><SCRIPT LANGUAGE="JavaScript">
>function MapSizeSelected(){
>     var aForm = document.forms[0]
>     if (document.forms[0].MapSize.selectedIndex != 0 &&
>         document.forms[0].MapSize.selectedIndex !=1){
>         aForm.zoomdir.value = "0";
>         aForm.submit()
>     }
>}
></script>
>
>My problem is that when the form gets submitted, even on this first time,
>the combo box does not select the actual mapsize value. Therefore, on the
>first sumbit the size (from the map file - 500 400) does not get selected.
>When the user slects another value, say 600 500, the mapsize does change but
>the 600 500 value does not get selected after the submit.
>
>I've spent all day on this and cannot figure it out. Hope you can assist.
>
>Thanks,
>
>Steve


There is no mechanism in HTML to automatically set a form control to an 
arbitrary value. So each time the page is sent to the browser it has the 
default values for the controls you have to use some JavaScript to set the control after the page has loaded. A simple example looks like this:

// this function gets call when the page has loaded
// widths 440 and 670 are based on my options (see below)
function init() {
     if ([mapwidth]==440) i=0;
     else if([mapwidth]==670) i=1;
     else i=2;
     document.form1.map_size.options[i].selected=true;
}

<!-- onLoad calls init() -->
<BODY onLoad="init();">

<SELECT name="map_size" onChange="reSize();" class="txt11px">
     <OPTION value="440 330">Small</OPTION>
     <OPTION value="670 503">Medium</OPTION>
     <OPTION value="900 675">Large</OPTION>
</SELECT>

This is as simple as it gets. There are more sophisticated examples out 
there. Search around and steal the code from pages you like. Remember you can always view the javascript contained in a page.

Rich

Richard W. Greenwood, PLS
(307) 733-0203
Rich at GreenwoodMap.com
www.GreenwoodMap.com 


**********************************************************************
CONFIDENTIALITY:   The information contained in this 
electronic mail message and any electronic files attached 
to it may be confidential information, and may also be the 
subject of legal professional privilege and/or public interest 
immunity.  If you are not the intended recipient you are 
required to delete it.  Any use, disclosure or copying of 
this message and any attachments is unauthorised.  If you 
have received this electronic message in error, please 
inform the sender or contact securityscanner at police.qld.gov.au.

This footnote also confirms that this email message has 
been checked for the presence of computer viruses.
**********************************************************************





More information about the mapserver-users mailing list