HTML legends

Ken Boss Ken.Boss at DNR.STATE.MN.US
Tue Dec 21 15:29:06 EST 2004


Hello Bob--

>All,
>
>I figured out how to filter for the layers that are DEFAULT for a
given
>zoom Value, I still haven't been able to figure out how to :
>
>    * Filter out the Labels in the LEGEND output.  I don't want to
see
>      them in the legend.

Not sure what you mean by "filter out the labels".  Are you saying that
you have ANNOTATION layers that you don't want to be represented in the
legend?  These should be excluded from the legend by default.

You can take a measure of control over what layers show up in the
legend by specifying an metadata field to use with the
ORDER_METADATA=some_metadata_field parameter, and then setting the value
for that metadata field to a negative number for layers that you don't
want to show up in the legend.

Alternatively, one workaround that I've used to give myself more
control over what is/isn't shown in the legend is to set an attribute in
the METADATA section of the layers that I want displayed, and then
enclose all of my legend template processing in a conditional test that
requires that variable to be set.  I've called this attribute
LEGEND_DISPLAY_LEVEL (I set it to one of three values for fine-tuning
legend display, but all that really matters in this discussion is
whether the variable is or is not set for a given layer).  For example:

(In the mapfile)

  LAYER
    NAME "Township Boundaries"
    GROUP pls
    STATUS OFF
    DATA /v03/data/shapefiles/twprgpy3w
    TYPE POLYGON
    CLASS
      OUTLINECOLOR 153 153 153
      SYMBOL 0
    END
    MAXSCALE 600000
    METADATA
      GROUP_MAXSCALE "600000"
      LEGEND_TITLE "Public Land Survey"
      LEGEND_META_GROUP "foreground"
      LEGEND_DISPLAY_LEVEL "2"
    END
  END # townships

(In the legend template)

[leg_group_html]
  [if name=legend_display_level oper=isset]
    .... (leg_group processing)
  [/if]
[/leg_group_html]

[leg_layer_html opt_flag=0]
  [if name=legend_display_level oper=isset]
    <tr>
      .... (leg_layer processing)
    </tr>
  [/if]
[/leg_layer_html]

[leg_class_html opt_flag=0]
  [if name=legend_display_level oper=isset]
      .... (leg_class processing)
  [/if]
[/leg_class_html]



>    * I can't seem to figure out how to make the check boxes do thier
>      thing.  (Question here, I have most of my layer set to DEFAULT,
>      how do I them OFF with the Legend controls? or do they need to
be
>      set to ON and called specifically.  If so, how do I initialize
the
>      interface with the approraite layers for a given Zoom.

If you have a layer set to DEFAULT in the mapfile, it's going to be on
all the time no matter what you do.  I think you want to set them to
either ON or OFF for initialization purposes.

As far as zoom is concerned, by default layers will only display in the
legend when they are within their associated MINSCALE/MAXSCALE bounds
(if set).  You can force legend display of out-of-scale layers with the
opt-flag=<bit_mask> parameter, like:

[leg_layer_html opt_flag=1]
  ...
[/leg_layer_html]

>I've been putzing with this all day, and this is all I have to show
for it:
>
>   [leg_layer_html ]
>        <input type=checkbox name=layer value=[leg_layer_name]
>             [if name=layer_status oper=eq value=2]CHECKED[/if]
>             [if name=layer_status oper=neq value=1][/if]/>
>   [/leg_layer_html]
>   [leg_class_html ]
>        <img src=[leg_icon] /> [leg_class_name]<br />
>   [/leg_class_html]
>
>
>This output the correct Layers (except for filtering out the LABEL
layers)
>

First thing I notice here is that you've got an extra "/" before the
">" that closes your input tag.  That might be enough to prevent your
checkboxes from working.  Outside of that, layer_status=2 means DEFAULT,
which means always on, so it doesn't make sense even to have a checkbox
for these.  I think what you want is probably something more like:

   [leg_layer_html]
        <input type=checkbox name=layer value=[leg_layer_name]
             [if name=layer_status oper=eq value=1]CHECKED[/if]
             [if name=layer_status oper=neq value=0][/if] >
   [/leg_layer_html]

Or follow the example in the docs at
http://mapserver.gis.umn.edu/doc44/html-legend-howto.html, which says
that:

[if] tag can be used to maintain the state of a layer checkbox

   [leg_layer_html order_metadata=legend_order opt_flag=5]
   <tr>
       <td>
           <input type=checkbox name="map_[leg_layer_name]_status"
            value=1 [if name=layer_status oper=eq value=2]CHECKED[/if]
>
       </td>
       <td colspan=2>
           <a href="[metadata name=href]">[metadata
name=layer_title]</a>
       </td>
   </tr >
   [/leg_layer_html]

Except I think you want [if name=layer_status oper=eq
value=1]CHECKED[/if] (that is, value=1, not value=2).

HTH,

--Ken Boss
  MN DNR Forestry Resource Assessment



More information about the mapserver-users mailing list