[Chameleon] javascript to turn on a layer

Julien-Samuel Lacroix jlacroix at mapgears.com
Tue Mar 14 10:45:54 EST 2006


Hello,
Your funciton should look like:

     function becomeAerial()
     {
         for(i=0;document.forms[0].elements['legendlayername[]'][i];i++)
         {
 
if(document.forms[0].elements['legendlayername[]'][i].value=="Aerial")
             {
 
document.forms[0].elements['legendlayername[]'][i].checked=true;
             }
         }
         document.forms[0].submit();
     }

Note that:
- the forms take an 's'
- the access to form elements with '[]' in the names is special.
- in the if() statement, the value should be equal (==) to "Aerial" not 
different (!=).

Julien


JR Santillan wrote:
> Hello all.
> 
> I am trying to use javascript to turn on a layer (an aerial photograph) 
> but its not working. Jacob Delfos gave a rough draft of the script and i 
> experimented on it. (I am not knowlegdeable in Javascript.)
> 
> In the map file, the layer name for the aerial photograph is "Aerial".
> 
> Here's the script:
> 
>             <a href="javascript:becomeAerial()">Go to aerial mode</a>
> 
>             <script>
>             function becomeAerial()
>             {
>                
>                 for(i=0;i<document.form[0].legendlayername[].length;i++)
>                     {
>                         
> if(document.form[0].legendlayername[i].value!="Aerial")
>                             {
>                                 
> document.form[0].legendlayername[i].checked=true;
>                             }
>                     }
>                 document.form[0].submit();
>             }
>             </script>
> 
> 
> and the Legend Layer Template is:
> 
> 
> [leg_layer_html order=ascending opt_flag=15]
>   <tr bgcolor="#ffffff">
>     <td><input type="radio" name="my_legend" 
> onclick="CWCSelectLayer('[leg_layer_name]', true)"[if name=selected 
> value=1] CHECKED[/if] ></td>
>     <td align="center" width=20><input type="checkbox" 
> name="legendlayername[]"
> value="[leg_layer_name]"
>     [if name=layer_status oper=eq  value=1]CHECKED[/if]
>     [if name=layer_status oper=eq value=2]CHECKED[/if]></td>
>     <td><img src="[leg_icon width=20 height=18]" width="20" height="20"</td>
>     [if name=wms_name oper=isnull]
>     <td><a href="#" 
> onclick="javascript:LegendTemplateLayerInfo('[leg_layer_name]');"><span 
> class="label">[leg_layer_name]</span></a></td>
>   </tr>
>     [/if]
>     [if name=wms_name oper=isset]
>     <td><a href="#" 
> onclick="javascript:LegendTemplateLayerInfo('[leg_layer_name]');"><span 
> class="label">[metadata name=WMS_TITLE]</span></a></td>
>   </tr>
>     [/if]
> [/leg_layer_html]
> 
> 
> 
> ---
> 
> I hope somebody could help. Thanks.
> 
> 
> Jojin
> 
> ------------------------------------------------------------------------
> Brings words and photos together (easily) with
> PhotoMail 
> <http://us.rd.yahoo.com/mail_us/taglines/PMall/*http://photomail.mail.yahoo.com> 
> - it's free and works with Yahoo! Mail.
> 
> 
> ------------------------------------------------------------------------
> 
> _______________________________________________
> Chameleon mailing list
> Chameleon at lists.maptools.org
> http://lists.maptools.org/mailman/listinfo/chameleon

-- 
Julien-Samuel Lacroix
Mapgears
http://www.mapgears.com/


More information about the Chameleon mailing list