How to create a legend containing ONLY classes shown in current map?

Ken Lord kenlord at GMAIL.COM
Wed Nov 24 12:57:54 EST 2004


Dave,

I do use conditional statements in my html legend templates for other
purposes ... the mapserver cgi conditional statements combined with
javascript to colour the table rows of a dynamic legend according to
groups of layers, but otherwise no,  as long as any part of a layer is
within a scale at which it could be drawn on the map, all the classes
of a layer will still be shown in the legend.

The naming scheme I use simply puts the burden on the user of the map
to understand that a layer may be on, but that some of the classes may
not be visible at a particular range of scales ... but at least the
user can see in the class names at what scales the different classes
will be visible and zoom in or out accordingly.

I could imagine a more complicated package of javascript in the
templates, that could detect the layer names and hide them when
appropriate, but it would add work, hardcoding layer names in the
javascript, for you any time you add a new layer to the map file,
probably not worth the effort, and the user may never even realize
that there is more data available to be seen if he/she zooms in or
out.

Eduardo,

I have also had the problem you describe, wanting to hide the layers
off the legend if you are panned out of the extent of the layer.
Perhaps if you were storing all the features in PostGIS, and worked
some extra queries of the database into your system you could
accomplish this, but again, probably not worth the effort in my
opinion and it might lead to unneeded confusion for the user if its a
dynamic legend that also switches the layers on and off.

Either way, there are lots of ways availble to customize how the
legend is implemented. For example, a simple ASP page on the side that
modifies '&layer=xxx' variables in the mapserver URL will give you
controls in the legend to turn groups of layers on and off together.

Cheers,
Ken Lord
Vancouver BC


On Wed, 24 Nov 2004 08:55:15 -0600, David Fawcett
<david.fawcett at state.mn.us> wrote:
>
>
> Ken,
>
> So then based on your naming scheme, I assume that you use conditional
> statements in your html legend template to determine which classes
> should show?
>
> (html legend info at
> http://mapserver.gis.umn.edu/doc42/html-legend-howto.html)
>
> David.
>
> David J. Fawcett
> MN Office of Environmental Assistance
>
> >>> Ken Lord <kenlord at GMAIL.COM> 11/23/2004 5:30:36 PM >>>
> MapServer CGI will not hide individual classes based on map scale in
> the way that you are hoping to do.
>
> The way I have attacked this is to place the scale range at which the
> class is visible within the name of the class, so that the name of the
> class and its viewable scale range is listed in the legend.
>
> hypothetical example of names given to classes in a layer that
> displays highways/roads/trails at different scales:
>
> Highway < 1:50,000
> Local Roads < 1:20,000
> Trails < 1:5,000
>
> Cheers,
> Ken Lord
> Vancouver BC
>
> On Tue, 23 Nov 2004 11:08:24 -0600, Daniele Margotti
> <margottid at comune.lugo.ra.it> wrote:
> > Hi,
> > I have another question about the legend...
> >
> > How can I tell CGI Mapserver to create a legend containing ONLY
> classes
> > that are visible in the current map?
> >
> > Now I get a legend that contains ALL classes of the selected layer,
> even
> > if I have zoomed to a very close scale (and I view only one class in
> the
> > map).
> >
> > Can you help me?
> > Is it possible?
> >
> > Thank you,
> >  Daniele
> >
>



More information about the mapserver-users mailing list