Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

Openlayers and GeoExt for producing a web map. The map has a legend panel generated by GeoExt. By default, GeoExt grabs the details of every layers from the map and create a legend for all the layers. However, I would like to exclude some of the layers to be displayed from the legend, what should I do to achieve this?

    legendPanel = new GeoExt.LegendPanel({
    map: map,
    title: 'Legend Panel',
    renderTo:'description',
    border: false,
    autoScroll: true,
    defaults: {
        style: 'padding:5px',           
        baseParams: {
            FORMAT: 'image/png',
            LEGEND_OPTIONS: 'forceLabels:on;fontName=Verdana;fontSize:11'
            }
        }
    });

Thanks!

share|improve this question
add comment

1 Answer

up vote 1 down vote accepted

There is actually quite detailed documentation about the issue here. Here's some quotes from the site relating to your issue.

The LegendPanel will include legends for all the layers in the layerStore it is configured with, unless the layer is configured with displayInLayerSwitcher: false, or a layer record has a hideInLegend field with a value of true. Additional filtering can be done by configuring a filter on the LegendPanel.

Here is my guessing code that applies the filter function:


    legendPanel = new GeoExt.LegendPanel({
    map: map,
    title: 'Legend Panel',
    renderTo:'description',
    border: false,
    autoScroll: true,
    filter: function(record){
        //Your filter function goes here, note that the function is processed on each layer.
        // Return false for those layers you want to exclude.
    },
    defaults: {
        style: 'padding:5px',           
        baseParams: {
            FORMAT: 'image/png',
            LEGEND_OPTIONS: 'forceLabels:on;fontName=Verdana;fontSize:11'
            }
        }
    });
share|improve this answer
    
Thanks. Where in the code shall I apply the filter setting? I tried something like this but it is not working: legendPanel = new GeoExt.LegendPanel({ map: map, title: 'Legend Panel', renderTo:'description', border: false, autoScroll: true, defaults: { showTitle: false, style: 'padding:5px', baseParams: { FORMAT: 'image/png', LEGEND_OPTIONS: 'forceLabels:on;fontName=Verdana;fontSize:11' } }, loader: { filter: function(record) { return record.get("layer").name.indexOf("locals") !== -1 } } –  user1829700 Jun 19 '13 at 6:34
    
Never used GeoExt before, but I paste my guessing code to apply filter function. Hope it helps. –  Mingfeng Jun 19 '13 at 6:44
    
Thanks Mingfeng. It works ! –  user1829700 Jun 19 '13 at 12:58
    
Glad I could help –  Mingfeng Jun 19 '13 at 14:50
add comment

Your Answer

 
discard

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.