Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

i have my map running over geoserver and openlayers. but i want to add a search box to find places in it. Well not specifically places but directions.

The map reads the layers directly over geoserver ( without postgis) but i'm a bit lost with the search thing.

How can i implement this feature and what tools are appropriated for it?

Now i will explain how the searching process must be:

1.- I have layers with streets, blocks and house numbers.

2.- the user will search by street name or house direction (house number and street name) and the map will show a list of concordances, if the user select one result on the list it will be zoomed to the destination. Very similar to an Arcgis search tools.

Any help will be appreciated.

share|improve this question

You can preatty easily run a search by combining WFS anc CQL like in the following example:

layerQueryRun: function() {
    var wfs = new OpenLayers.Protocol.HTTP({
        url:WMSCONFIG.wfs_server_path+"?service=wfs&version=1.0&request=GetFeature&typename=" + youLayerTypeName,
        format: new OpenLayers.Format.GML.v3({})

    // start spinner
    Maps.set("isLoading", YES);{
            "CQL_FILTER":"STREET = 'Godric Hollow' AND NUMBER=1"
        callback: this.didFetchWfsFeatures

didFetchWfsFeatures : function(response, options) {
    try {
        var gml = new OpenLayers.Format.GML({extractAttributes: true});
        response.features =;
    } catch(e) {
    // stop spinner
    Maps.set("isLoading", NO);

The CQL reference is available here.

Once you have loaded the features from the results (in doSomethingWithFeatures) you can render them to HTML and bind an event listener to each so that when a feature is clicked the application is notified and it can zoom the map to the feature bounds.

The features returned from the WFS call have both attributes and geometry. Please note that the geometry will be in the original layer's projection which could be different from what you are using in OpenLayers (I guess 900913?). In that case you can either:

  • use proj4js to handle the conversion for you in the browser

  • reproject the original data

share|improve this answer
Thank you for answer =), but i have a map works with wms layers, your code is adaptable to this protocol or i should have to switch to wfs? – Daeron Alcarin Dec 16 '11 at 16:31
You can mix and match WFS and WMS anyway you want: WMS for massive rendering, WFS for single features and searches – unicoletti Dec 16 '11 at 19:38
ok, got it =) Thanks for your help. – Daeron Alcarin Dec 16 '11 at 20:06
this is helpful, but any working example in the implementation? – Sachi Tekina Aug 13 '15 at 1:36

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.