0

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,

Gery
  • 8,390
  • 3
  • 22
  • 39

1 Answers1

1

Just remove the "%". Use

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

instead of

return record.getLayer().name.indexOf("%beam%") == -1;
  • thanks for the reply, but using your suggestion gives `Uncaught TypeError: Cannot read property 'indexOf' of null`. Afaik, this means that `name` (thus `indexOf`) are null or empty. That can be true because no layers have been uploaded yet, but the idea is to apply this filter once layers are uploaded. Any additional idea? – Gery Jun 02 '15 at 01:02
  • 2
    Hard to say what the problem is without seeing the full code. See the working example here: http://jsfiddle.net/igor23/a1nkt9vk/ . In this example, legend panel doesn't show legend image for layer named "beam". Hope this helps. – igor-chernikov Jun 02 '15 at 05:27
  • thanks!! I found the solution! – Gery Jun 03 '15 at 03:20