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( { 
        drillDown:true, 
        //layers: sniLayers_conGetInfo,
        layers: [],        
        queryVisible:true,
        infoFormat: 'text/html',
        handleResponse: function(xy, request) {
	       
	        var doc = request.responseXML;
	        if(!doc || !doc.documentElement) {
	            doc = request.responseText;
	        }
	        var features = this.format.read(doc);
	        
	         if(doc!="") this.triggerGetFeatureInfo(request, xy, features);
	        
	    }
        //infoFormat: 'application/vnd.ogc.gml'
        
    });
    getinfo11.events.on({
        "getfeatureinfo": function(e) { 
            //alert(e.text);
            // e.features[0]
            /*
             location
                OpenLayers.Feature.Vector or OpenLayers.LonLat or OpenLayers.Pixel or OpenLayers.Geometry A location for this popup’s anchor.
            map
                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,
                width:400,
		height: 300,
                html: e.text,
                map: mapPanel,
                maximizable: false,
                collapsible: false,
                autoScroll: true
            });
            popup1.show();
        }
    });
    
    getinfo11.events.register("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(){ } });
    mapToolBar.add(botInfo);

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"){
            layerInfo.push(layers[i]);
            yaHuboSubcadena = true;
        }

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

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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 )

Google+ photo

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

Connecting to %s