Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Is it a possibility in OL to add a legend (symbology) directly to (under) particular layer (not only switch on/off the layer)?

share|improve this question
up vote 2 down vote accepted

This functionality is not available in OpenLayers trunk. Other toolkits -- such as GeoExt -- or other extended functionality -- as demonstrated in the previously-linked sandbox -- may provide this functionality, but none are available in the stock/base OpenLayers install.

share|improve this answer
Great. Thank's for clear answer! – com Aug 31 '10 at 17:19

Assume in the Legend [Table of Contents/Layers] you still want to show map layers with on/off switch but with the symbology of each under each one.

Such as:

View Source reveals that it is using Web Map Context (WMC)

var format = new OpenLayers.Format.WMC({'layerOptions': 

var xmlParser = new OpenLayers.Format.XML()

(XML is 'hidWMC' at bottom of source code)

 // add the LayerSwitcher (a.k.a. Map Legend)
                layerSwitcher = new OpenLayers.Control.LayerSwitcher();
                layerSwitcher.ascending = false;
                layerSwitcher.useLegendGraphics = true;


Try recreating the example then change for your requirements (content)

share|improve this answer
Yes it was exactly my idea. How can i do it? – com Aug 31 '10 at 16:49
updated answer - with code from the example source – Mapperz Sep 1 '10 at 1:54

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.