[OpenLayers-Users] Display legend

Andrew de Klerk andrew.deklerk at gmail.com
Wed Oct 15 11:09:31 EDT 2008


A bit long winded, but we use the “GetLegendGraphic” Request to request the graphic for each class and then place them in a div outside of the map (div could be placed on top of map as well). The "LAYER" is your class name for that particular layer. I cannot recall why we never used GetLegend - there must have been a reason..............but..... this works for us ☺.

<div id="legend" style="text-align:left; display:none; position:absolute; z-index:777;cursor:pointer; border:1px solid #a9a9a9; background-color:White;">
                <img src="http://localhost/wms/streetmap.asp?SERVICE=WMS&VERSION=1.1.1&REQUEST=GetLegendGraphic&LAYER=Provinces&Format=image/png" alt="" style="border:none;"/><br />
                      <img src="http:// localhost /wms/streetmap.asp?SERVICE=WMS&VERSION=1.1.1&REQUEST=GetLegendGraphic&LAYER=Capital_Towns&Format=image/png" alt="" style="border:none;"/><br />
                      <img src="http:// localhost wms/streetmap.asp?SERVICE=WMS&VERSION=1.1.1&REQUEST=GetLegendGraphic&LAYER=Major_Towns&Format=image/png" alt="" style="border:none;"/><br />
                      <img src="http:// localhost /wms/streetmap.asp?SERVICE=WMS&VERSION=1.1.1&REQUEST=GetLegendGraphic&LAYER=Secondary_Towns&Format=image/png" alt="" style="border:none;"/><br />
                      <img src="http:// localhost wms/streetmap.asp?SERVICE=WMS&VERSION=1.1.1&REQUEST=GetLegendGraphic&LAYER=Other_Towns&Format=image/png" alt="" style="border:none;"/><br />
                      <img src="http:// localhost /wms/streetmap.asp?SERVICE=WMS&VERSION=1.1.1&REQUEST=GetLegendGraphic&LAYER=Minor_Towns&Format=image/png" alt="" style="border:none;"/><br />
</div>

Andrew

From: users-bounces at openlayers.org [mailto:users-bounces at openlayers.org] On Behalf Of Sophie GRAS
Sent: 15 October 2008 04:54 PM
To: users at openlayers
Subject: [OpenLayers-Users] Display legend

Hi everyone

I have a dumb question but i can't find the answer...
I have a mapfile with several layers and I use openlayers to display them.
In each layer I have some classes (representing percentage of the population) and I'd like to know how to display the legend of these classes using openlayers.
If i embed the legend in the mapfile, it works well but the legend is displayed on each tile. Is there a way to act differently?

Thanks

No virus found in this incoming message.
Checked by AVG - http://www.avg.com
Version: 8.0.173 / Virus Database: 270.8.0/1721 - Release Date: 10/14/2008 9:25 PM




More information about the Users mailing list