[Chameleon] JSTreeView

Paul Spencer pspencer at dmsolutions.ca
Thu May 26 08:56:48 EDT 2005


Edith,

I would tackle this by doing the following:

1. add metadata to each of your layers called layer_index and make it 
sequential 0  - nLayers

2. build your legend template file like this:

[leg_group_html]
<input type=checkbox name='[leg_group_name]' onchange="toogleGroup( this 
)">[leg_group_name]<br>
[/leg_group_html]
[leg_layer_html]
<input type='checkbox' id='layer_[layer_group]_[metadata 
name=layer_index]' name='legendlayername[]' value='[leg_layer_name]' 
onclick='toggleLayer( this )'>[leg_layer_name]<br>
[/leg_layer_html]


3. add a couple of javascript functions to your template

function toggleGroup( obj )
{
   var nLayers = 20; //set to number of layers in map file
   for(i=0; i<nLayers; i++)
   {
     var layer_cb = document.getElementById( 'layer_'+obj.name+'_'+i );
     if (layer_cb)
       layer_cb.checked = obj.checked;
   }
}

function toggleLayer( obj )
{
   var group = (obj.id.split( "_" ))[1];
   var group_cb = document.getElementById( group );
   //case 1: unchecked layer, can uncheck the group
   if (group_cb)
   {
     if (!obj.checked)
     {
       group_cb.checked = false;
       return;
     }
     else // now have to check all the layers in this group
     {
       var nLayers = 20; //set to number of layers in map file
       for(i=0; i<nLayers; i++)
       {
         layer_cb = document.getElementById( 'layer_'group+'_'+i );
         if (cb && !cb.checked) //stop if any are unchecked
         {
           group_cb.checked = false;
           return;
         }
       }
       group_cb.checked = true; //all checked, can turn on group
     }
   }
}

Note this code is extremely rough and completely untested.  Good Luck!!!

Cheers

Paul

Edith TAKI wrote:
> Hi,
>  
> Thank you Ferencik for your solution but you don"t need to 
> select/unselect layers in a group for your solution ...
>  
> My legend is generated dynamicaly with mapfile and legend_template and 
> look like that
>  
> 
> Group 1
> 
>     *      layer 1
>     *      layer 2
>     *      layer 3
> 
> Group 2
> 
>     *      layer1
>     *      layer2
> 
>  
> and i have a checkbox for each line ; those for layers are coded like that :
>  
>         <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]>
>        
>      </span>
>  
> what i need now is to code the group so that a click on a group could 
> check ou uncheck the layers depending.
>  
> For map refreshing, I used CWCJSAPI and i just solve the problem of 
> navigation buttons like zoomin zoomout, they no longer refresh all the page;
> Only Update button need now to reload the page but I have no idea for 
> Javascript so it'll be difficult !!
>  
> Thank you for your help
> 
> */Jano Ferencik <ferencik.ioan at personal.ro>/* wrote:
> 
>     Hi Edith
> 
>     the situation is like this..I created a javascript treemenu wich I
>     am attaching
>     to this email as a zip archive....you can modify and use it
>     ....but....there are
>     2 things..
>     1 as long as The update Map widget refreshes the page You can do
>     nothing about
>     it... the menu will allways refresh and appear like on first
>     load...you could
>     solve this by creating some javascript handling some events...wich
>     will keep the
>     opened group open after refreshing....the script should use the :active
>     pseudoclass of group(wich in this case must be links)...(this is
>     only an advice
>     )...I though one tome to do it but could take me a loomng time as my
>     javascript
>     skills are only basic
> 
>     In my case I have another problem...I fave a huge number of layers
>     in may
>     Chameleon application(about 50) and I created a legend on multiple
>     levels...it
>     is refreshing i! tself on Update Map and second I think that the
>     number of layers
>     conducted to decreasing of speed when loading the map....
>     A possibble solution could be the new Ka-Map project from DM
>     solutions(ie. the
>     map doesn't refresh itslelf on the basic actions like panning or
>     zooming or
>     layer controls).....but you will have to wait for the application
>     Ka-map to be
>     released....i think it will happen soon(ask Paul Spencer about this) :))
> 
>     Regards
> 
> 
>      > Hi list,
>      >
>      > I have a problem similar to jstreeview ; I developped
>     legendTemplate to show
>     at page load only groups so the user could developp a group by
>     clicking its id
>     to show the layers in the group ; I have two problems :
>      > 1 - using Javascript to hide / show layers for each group.
>      > I think Jano Ferencik (who first posted about Jstreeview) succeed
>     doing
>      > this ; could you help me ?
>      > 2 - I have the same problem after Update, the page looks like on
>     the fisrt
>      > l! oading and user loose his environnment, only groups are visible.
>      >
>      > can somebody have any suggestions ?
>      >
>      > Thanks
>      >
>      >
>      >
>      >
>      > ---------------------------------
>      > Post your free ad now! Yahoo! Canada Personals
>      >
> 
> 
> 
> 
> 
>     ___________________________
>     Cv-ul tau ia 500 euro/luna!
>     http://500.myjob.ro
> 
> 
> ------------------------------------------------------------------------
> Post your free ad now! *Yahoo! Canada Personals* 
> <http://ca.personals.yahoo.com/>
> 
> 
> ------------------------------------------------------------------------
> 
> 
> <!-- LEGEND-->
>  [leg_group_html]
> </div> 
> <div id="[leg_group_name]">
> 
>     <div class="groupLabel">
>  
>   <input type="checkbox" name="legendgroupname[]" 
>                value="[leg_group_name]"
>         [if name=layer_status oper=eq  value=1]CHECKED[/if]
>         [if name=layer_status oper=eq value=2]CHECKED[/if]
>         onclick="checkAll();">
> 
>           <a href="javascript:void(0);" onclick="toggleLayer('[leg_group_name]_layer');">[leg_group_name] </a>
>     </div> <!-- GroupLabel-->
> 
> </div>
> <div id="[leg_group_name]_layer" style="display:none">   
>  [/leg_group_html]
> 
> [leg_layer_html order=ascending opt_flag=15]
> 
>   <div>
>     [if name=SHOWINLEGEND  oper=isnull]
>       <span class="layerTitle">
>         <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]>
>         
>      </span>
>       
>       <span>
>         <img src=[leg_icon]>
>       </span>
>      
>       
>         [if name=wms_title oper=isnull]
>           <span class="layerLabel"> [leg_layer_name] </span>
>         [/if]
> 
>         [if name=wms_title oper=isset]
>            <span class="layerLabel"> [metadata name=WMS_TITLE]  </span>
>         [/if]
>       
>    
>     [/if]
> 
>       [if name=SHOWINLEGEND oper=isset]
>          <input type="hidden" name="legendlayername[]" value="[leg_layer_name]">
>       [/if]
>    </div>
> [/leg_layer_html]
> 
> <script language="javascript">
> 
> function checkAll()
> {
> 
> }
> 
> </script>
> 
> 
> ------------------------------------------------------------------------
> 
> _______________________________________________
> Chameleon mailing list
> Chameleon at lists.maptools.org
> http://lists.maptools.org/mailman/listinfo/chameleon

-- 
+-----------------------------------------------------------------+
|Paul Spencer                           pspencer at dmsolutions.ca   |
+-----------------------------------------------------------------+
|Applications & Software Development                              |
|DM Solutions Group Inc                 http://www.dmsolutions.ca/|
+-----------------------------------------------------------------+


More information about the Chameleon mailing list