[mapserver-users] HTML Legend with Status Checking...

Martin, Daniel DMartin at erac.com
Thu Oct 3 13:21:29 EDT 2002


The biggest problem is that your solution locks your client to a specific
map.  With a more generic client, you can use as many different map files
with the same client as you'd like.  A separation of presentation from
content is generally a better solution in any web application, and
definitely true with MapServer, IMHO.

Perhaps it would be best if I share the HTML legend code I use.
Excerpt from my client:

<table cellpadding="0" cellspacing="1" border="0" bgcolor=#007D5A>
  <TR>
  	<TD bgcolor=#007D5A align=center>
  			<font face="arial" size=2 color=white>Legend</font>
  	</TD>
  </TR>
  <TR>
    <TD bgcolor=white>
      <table cellspacing=0 cellpading=0 border=0>
        <TR>
          <TD colspan=4 align=center>
            <input value="Turn All On" title="Click this button to turn all
layers on" class=legend type=button name=checkAll
onClick="checkAllLayers();submitMapserv();">
            <input value="Turn All Off" title="Click this button to turn all
layers off" class=legend type=button name=uncheckAll
onClick="uncheckAllLayers();submitMapserv();">
          </TD>
        </TR>
 	     <TR>
		    <TD>

           [legend]
 </TD>
</TR>
      </table>
    </TD>
  </TR>
</TABLE>

____________
Now for the legend template:

   [leg_layer_html opt_flag=2 order_metadata=legend_order]
          [if name=layer_status oper=neq value=2]
           <input title="Click here to turn the [leg_layer_name] layer [if
name=layer_status oper=neq value=0]off[/if][if name=layer_status oper=eq
value=0]on[/if]" type=checkbox name=layer value="[leg_layer_name]" [if
name=layer_status oper=neq value=0]CHECKED[/if] onClick="submitMapserv();">
					[/if]
   [/leg_layer_html]

   [leg_class_html opt_flag=2]	  
				</TD>
				<TD>
           <img src="[leg_icon]" border=0>
				</TD>
				<td>&nbsp;</td>
				<TD>	 
					 <font face="arial"
size=2>[leg_class_name]</font>
				</TD>
		</TR>
		<TR><TD>
   [/leg_class_html]

____________
Generic, but I think it accomplishes the same basic result, and should work
with almost any map.

-Dan

-----Original Message-----
From: Rob Holloway [mailto:rholloway_1999 at yahoo.com]
Sent: Thursday, October 03, 2002 7:03 AM
To: Martin, Daniel; 'woodbri at swoodbridge.com';
mapserver-users at lists.gis.umn.edu
Subject: RE: [mapserver-users] HTML Legend with Status Checking...


Hi

I've been following this thread with some interest as
well as I encountered a similar problem.  I'm fairly
new to Mapserver so forgive me if this a stupid
question but is there any reason that javascript can't
be used to control the legend. For example, I have
used the following code (thanks to suggestions from
the users list):

 <td valign=top>  
<script>
		if ([scale] < 100000){

	document.write("<input type='checkbox' name='layer'
value='buildings'  onclick='updateForm();'
[buildings_check]>Buildings");
  }
</script>

</td>

Although I haven't had a chance to do alot of testing
this seems to work fine at controling the layers that
appear in the legend based on scale. As I'm also new
to javascript, I guess my real question is does the
use of javascript slow down the performance of
Mapserver or make my application less compatable for
different browsers etc.?

Cheers

Rob

 


--- "Martin, Daniel" <DMartin at erac.com> wrote:
> > OK, I have been reading this thread with great
> interest and was 
> > wondering if you can summarize what you need to do
> to have multiple 
> > layers at different scales and only have the
> visible ones show up in 
> > your legend templates. 
> Here's my best shot:
> In MapServer we can have as many layers of the same
> name as we want.  The
> benefit is that these same-named layers will turn on
> and off together.  An
> HTML template will show each layer and class even if
> they have the same
> name, *assuming* they are all in scale.
> 
> However, if these same named layers have scales that
> do not overlap, you
> should never see both in the legend.  This gives you
> the effect of several
> layers acting as one, with MapServer automatically
> switching between them as
> you zoom in and out.  
> 
> As we found out in this thread, you MUST use
> MINSCALE and MAXSCALE in the
> LAYER object, not in the CLASS object, for it to
> work correctly in the HTML
> legend.
> 
> This also hinges on your opt_flag in your
> [leg_layer_html] tag.  If you use
> opt_flag=1 or a summation value of opt_flag that
> includes 1, then layers
> will show even when out of scale.  When I say a
> summation value, as the HTML
> Legend HOWTO indicates, if you want an opt_flag of 1
> and an opt_flag of 4,
> you set your opt_flag to 5.
> 
> My favorite use of this is streets.  I use this
> technique to create a street
> layer that, at high scale, uses a small single class
> highway layer.  If you
> look at the entire US the streets load in seconds. 
> When you zoom to a
> certain level MapServer switches to a very detailed
> street layer with many
> different classes that would be extremely slow to
> load at a higher scale.
> To the user this is seamless. 
> 
> One interesting addition I'll point out is that
> sometimes you may want to
> combine two layers into one even at the same scale,
> but only show one in the
> legend.  You can accomplish this by using
> [leg_layer_html
> order_metadata=legend_order] and then setting the
> legend_order meta data to
> -1 in one of the two layers:
> 
> METADATA 
>    legend_order "-1"
> END
> 
> >  I have a mapfile that was working great in a
> modified version of 
> >  gmap75 and in it all like layers have the same
> name and different 
> >  scales and it works great, except it always shows
> all the layers.
> In an HTML legend, this *should* only happen if you
> have an opt_flag=1 (or a
> summation value of opt_flag that includes 1). 
> Perhaps this was the case?
> 
> > I move the mapfile into the new maplab application
> and a bunch of my 
> > layers vanished. 
> Honestly, I've not used MapLab.  When you say
> "vanished", do you mean from
> the map itself, or only from the legend?  If you
> mean from the legend,
> perhaps the opt_flag is different in MapLab.
> 
> Hope that helps a little,
> Dan Martin
> 
> -----Original Message-----
> From: woodbri at swoodbridge.com
> [mailto:woodbri at swoodbridge.com]
> Sent: Tuesday, October 01, 2002 7:10 PM
> To: mapserver-users at lists.gis.umn.edu
> Subject: Re: [mapserver-users] HTML Legend with
> Status Checking...
> 
> 
> (I cc:'d this to maplab list)
> 
> 
> OK, I have been reading this thread with great
> interest and was 
> wondering if you can summarize what you need to do
> to have multiple 
> layers at different scales and only have the visible
> ones show up in 
> your legend templates. I think this is an area that
> could use more 
> documentation or at least user insights.
> 
> The variables seem to be:
> 
> group names
> layer names and scales
> class names and scales
> the option code in legend templates
> 
> and maybe a few others that I missed.
> 
> I have a mapfile that was working great in a
> modified version of 
> gmap75 and in it all like layers have the same name
> and different 
> scales and it works great, except it always shows
> all the layers.
> 
> I move the mapfile into the new maplab application
> and a bunch of my 
> layers vanished. I turns out the maplab generates
> urls like:
>   
>
...&layer[]=highway&layer[]=highway&layer[]=highway&...
> because I use the same name on all the like layers.
> So I think I have 
> it confused.
> 
> So your insight into the layers, names, scales etc
> might help me 
> figure this out.
> 
> 
> Thanks,
>   -Steve W.


__________________________________________________
Do you Yahoo!?
New DSL Internet Access from SBC & Yahoo!
http://sbc.yahoo.com



More information about the mapserver-users mailing list