[GIS] How to query a PostGIS database through Geoserver and OpenLayers

geoserveropenlayers-2postgis

I've built a web application using OpenLayers, which is connected to my PostGIS database through Geoserver. Now that I'm able to successfully display all of the layers, I'd like to add querying/interactivity capabilities to the map. For instance, I'd like to create a dropdown menu of checkboxes so the user could "Choose X who have done Y", another dropdown to "Choose X who haven't done Y", etc. I'm having trouble figuring out how exactly to add in this functionality. Does anybody know any good resources/examples for how I might go about doing this?

Thanks for your help.

Best Answer

Rather than using your client-side code to query your database (big security risk), I would suggest you use Geoserver's WFS filtering capabilities. Geoserver's WFS implementation supports a number of filtering techniques, including cross-layer filtering through the querylayer extension.

Here is an example implementation. The js in the source is not minified so it is readable.