[Chameleon] Splitting up a Legend widget

Mike Leahy mgleahy at alumni.uwaterloo.ca
Sun Dec 4 17:01:13 EST 2005

Hello Carlo/Peter,

This may or may not be of interest in this context, but one of the 
widgets I included in a package I posted earlier (available at 
http://gaia.uwaterloo.ca/mgl/) is a legend widget (named 'mcLegend' in 
the zip file downloadable at that link).  If you look at the code in 
that widget, you should find that there is no actual use of a MapServer 
legend template.  Instead, it uses PHP/MapScript to determine the 
contents of the map, and produce the HTML for the legend.  One of the 
features you'll notice in this widget is that it looks for a metadata 
tag called 'HIDEFROMLEGEND', where if that is set, the layer can be 
displayed in the map, but will not be visible in the HTML produced for 
the legend (instead it writes a checkbox for the hidden layer with 
style="display:none;" in a table row with style="height:0px;").  Also 
included in that code is a check for layers with multiple classes, so 
that you get a legend key for all classes (e.g., if you had a 
chloropleth map, you might want each class to appear with a description 
beside it).  Also, I should point out that this widget expects a group 
name to be given to each layer - that might be something you'd want to 

If the method used in that widget doesn't work for you, perhaps you can 
use a similar technique with the standard legend_template.html using an 
if/else statement based on a 'HIDEFROMLEGEND' meta tag.  I figure that 
could be used to determine whether you write a checkbox with the 
display:none style property, or maybe use a hidden input.

I hope this helps,

Carlo Tronnberg wrote:
> Hi there,
> I did the same with one of my projects, adding a meta tag for the layers 
> I wanted to handle separately, such as:
>    CONNECTION "user=elu password=pw dbname=db host=localhost"
>    DATA "the_geom from lineup"
>    FILTER "state = 'T'"
>    NAME "Timed-out Stations"
>            "isStation" "true"
>    END
>    CLASS
>        STYLE
>        SYMBOL 'TimeOutStation'
>        COLOR 0 0 0
>        OUTLINECOLOR 0 0 0
>        END
>    END # Class
>      "init=epsg:4326"
>    END
> Using the chameleon example, I modified the "legend_template.html" file 
> such as:
> [leg_layer_html order=ascending opt_flag=15]
> [if name=isStation oper=isnull]
>  <div id='[leg_layer_name]_t'><tr bgcolor="#ffffff" ID='[leg_layer_name]'>
>    <td valign="top" width="10"><input type="radio" 
> style="margin-top:1px; margin-bottom:1px; height:14px;" name="my_legend" 
> onclick="CWCSelectLayer('[leg_layer_name]', true)"[if name=selected 
> value=1] CHECKED[/if] ></td>
>    <td nowrap valign="top" width="18"><input type="checkbox" 
> style="margin-top:1px; margin-bottom:1px; height:14px;" 
> 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 valign="top" align="middle" width="15"><img border="0" 
> style="margin-top:0px; margin-bottom:0px; margin-right:0px;" 
> src="[leg_icon width=16 height=17]"></td>
>    [if name=wms_name oper=isnull]
>    <td valign="top" nowrap><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 valign="top" nowrap><a href="#" 
> onclick="javascript:LegendTemplateLayerInfo('[leg_layer_name]');"><span 
> class="label">[metadata name=WMS_TITLE]</span></a></td></tr>
>    [/if]</div>
> [/if]
> [/leg_layer_html]
> I duplicated the LegendTemplate widget so as to have 2 different 
> versions of it in the same page (Just copy the widget and rename it...). 
> One of them showing all the layers without that meta data and the other 
> one the layers with it (using in my case the condition: [if 
> name=isStation oper=isset] ).
> I have a trouble though: I wish to define layers in the map file which 
> would NOT be handled by the automatic layer functions in chameleon. I 
> want to be able to show or hide them but NOT promote/demote or delete 
> them. Whatever dynamic map modification done, these "static" layers 
> should always be there on top of any other layer, even if other layers, 
> such as WMS layers are added by the user. Is this feasible?
> I really hope somebody can help me with this.
> Greetings,
> Carlo
> ----- Original Message ----- From: "Paul Spencer" <pspencer at dmsolutions.ca>
> To: "Peter Kingsbury" <peter.kingsbury at gmail.com>
> Cc: <chameleon at lists.maptools.org>
> Sent: Sunday, December 04, 2005 16:51
> Subject: Re: [Chameleon] Splitting up a Legend widget
>> Peter,
>> I've never seen this before.  The only approach I can think of is to  
>> put metadata into your layers to place them into the 'left' or  
>> 'right' side, the construct two legend templates that restrict  
>> contents based on this metadata, then have two LegendTemplate widgets  
>> that use two different templates.
>> Cheers
>> Paul
>> On 4-Dec-05, at 9:24 AM, Peter Kingsbury wrote:
>>> Hi all,
>>> I have a mapserver whose LegendTemplate widget is currently  
>>> displaying enough layers to require a user to vertically scroll  
>>> farther than I would like.
>>> I am researching a method of dividing the legend up into two  halves, 
>>> such that one half is displayed on either side of the  MapDTML widget 
>>> which is in the center of my site.
>>> Is there a means of accomplishing this?
>>> Best regards,
>>> - Peter
>>> _______________________________________________
>>> 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/|
>> +-----------------------------------------------------------------+
> _______________________________________________
> Chameleon mailing list
> Chameleon at lists.maptools.org
> http://lists.maptools.org/mailman/listinfo/chameleon

More information about the Chameleon mailing list