Search code examples
filterpanelopenlayerslegendgeoext

Filter (no display) layers in GeoExt.LegendPanel using LIKE operator


This works to avoid Basemap layers such as Google Maps and overlays such as WMS to appear in the GeoExt Legend Panel:

var legendPanel = new GeoExt.LegendPanel({
    border: false,
    filter: function(record){
        if(!(record.getLayer().isBaseLayer) && (record.getLayer() instanceof OpenLayers.Layer.WMS)){
        return true;
        }
    } });

The problem is that I need to filter (ie. no display) layers with names having "beam" in their names, I tried with no success this:

return record.getLayer().displayInLayerSwitcher == false && record.getLayer().name == '%beam%';
return record.getLayer().displayInLayerSwitcher == false &&
record.get("layer").name.indexOf("%beam%") == -1;
return record.get("layer").name.indexOf("%beam%") == -1;

Any hints are welcomed,


Solution

  • Just remove the "%". Use

    return record.getLayer().name.indexOf("beam") == -1;
    

    instead of

    return record.getLayer().name.indexOf("%beam%") == -1;