I am using GeoExt for my web mapping project. My web map includes a legend generated by GeoExt. Is it possible to turn off the layer title for a specific layer in legend? I am aware that there is a showTitle property for GeoExt.WMSLegend. However setting this property to false will turn off the layer titles of all the layers in the legend. Is there any way to turn off the layer title of just one single layer?

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

The answer lies in the LayerLegend.js file (not obvious): when a new element is made in the legend, the title is determined by different tests:

  • if 'legendTitle' has been set in the defaults, this title will be used
  • the attribute 'hideTitle' (boolean) of the layer record (not the OpenLayers.Layer object, but the GeoExt.data.LayerRecord object) is checked, if it is true, then no title will be displayed
  • the attributes 'title' then 'name' are then checked
  • if none of theses attributes are found, then the OpenLayers.Layer object's name will be used.

So, you have to set the attributes 'hideTitle' to conditionally mask the layer's title in the legend. You can also customize the title of the layer, in case you'd like to use the layer's title as title of a group of layers. In that case, 'showTitle' in the LegendPanel has to be set to true.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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