To retrieve feature info for a polygon selection, I have the OpenLayers code below:
var featureTypes = ["nig_admin1", "nig_admin2", "nig_admin3", "nig_landscan"];
var populationCtrl = new OpenLayers.Control.GetFeature({
protocol: OpenLayers.Protocol.WFS.fromWMSLayer(nig_landscan, {
url: "http://localhost:8081/geoserver/wfs",
featureType: featureTypes
}),
hover: false
});
populationCtrl.events.register("featureselected", this, function(e){
select.addFeatures([e.feature]);
});
I'd like to view the features retrieved in a pop up, or something similar. I've tried adding a pop up code within the featureselected
event, but I can't get anything to show. Any pointers on how I can proceed will be highly appreciated.
nig_landscan
in the code above refers to the corresponding WMS layer, which is a layer group in GeoServer.
My environment setup: GeoServer 2.1.3, PostGIS 1.5, OpenLayers 2.11.
Best Answer
Using WFS with filters, I was able to contruct a filter that retrieves info for the selection only. My code is as shown below:
In this, I'm using WPS chained with WFS(with filter containing info about the selected geometry). From the code above,
getGeometryFilter(getWkt(geometry))
parses my geometry into WKT format, and constructs a valid filter. The filter is shown below:In my case, I was calculating population for the selected region. So, I constructed a
gs:Aggregate
request using theWPS request builder
. I then passed the filter above to it. This is done in thegetWPSRequestData(filter)
method. This method is trivial if you use the WPS Request Builder.My actual request is sent in the
sendWPSRequest(wpsRequestData);
function. Its details are shown below:I'm sending my request via POST, and using
OpenLayers.Format.GML
class to deal with the GML response.