Using beforeGetFeatureInfo event for filtering layers to get info

*For OpenLayers 2.13

Put an empty array as layers property in WMSGetFeatureInfo (We will generate the layer array in the event): line 4

Suscribe event: line 47

   getinfo11 = new OpenLayers.Control.WMSGetFeatureInfo( { 
        //layers: sniLayers_conGetInfo,
        layers: [],        
        infoFormat: 'text/html',
        handleResponse: function(xy, request) {
	        var doc = request.responseXML;
	        if(!doc || !doc.documentElement) {
	            doc = request.responseText;
	        var features =;
	         if(doc!="") this.triggerGetFeatureInfo(request, xy, features);
        //infoFormat: 'application/vnd.ogc.gml'
        "getfeatureinfo": function(e) { 
            // e.features[0]
                OpenLayers.Feature.Vector or OpenLayers.LonLat or OpenLayers.Pixel or OpenLayers.Geometry A location for this popup’s anchor.
                OpenLayers.Map or GeoExt.MapPanel The map this popup will be anchored to (only required if anchored is set to true and the map cannot be derived from the location‘s layer.
            var popup1 = new GeoExt.Popup({
                title: 'Información',
                location: e.xy,
		height: 300,
                html: e.text,
                map: mapPanel,
                maximizable: false,
                collapsible: false,
                autoScroll: true
    });"beforegetfeatureinfo", null, onBeforeGetFeatureInfo); 
    var botInfo = new GeoExt.Action({
        iconCls: 'info', 
        tooltip: "Información", 
        toggleGroup: 'draw',
        control: getinfo11,
        map: map
    //var botInfo = new Ext.Toolbar.Button({ iconCls: 'info', tooltip: "info", handler: function(){ } });

Write function to filter repeated layers “subcadena”:

function onBeforeGetFeatureInfo(event)
  // build CQL_FILTER param list from active info layer CQL_FILTER params
  var layers = sniLayers_conGetInfo;
  var filter = "";
  var layerInfo = [];
  var yaHuboSubcadena = false;
  for (var i = 0, len = layers.length; i < len; i++) {
    if(layers[i].visibility === true){
        if(yaHuboSubcadena === false && layers[i].params.LAYERS[0] === "difare:subcadena"){
            yaHuboSubcadena = true;

        if (layers[i].params.LAYERS[0] !== "difare:subcadena"){
  getinfo11.layers = layerInfo;
  //getinfo11.vendorParams = { 'VIEWPARAMS': filter };

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s