My code works normally but I want to add a search box and with coming value (like addresses) which I search on WMS and focus on those for which value exists. I mean like that I have search box and I give the parameters for example New York Washington Apartment and in the background search on WMS and zoom to New York Washington and select. I searched samples but I didn't find how I can do that.

map = new OpenLayers.Map('map', options);               
                var tiled = new OpenLayers.Layer.WMS(
                        LAYERS: 'bla',
                        STYLES: '',
                        format: "image/png",
                        tiled: true,
                        tilesOrigin : map.maxExtent.left + ',' + map.maxExtent.bottom
                        buffer: 0,
                        displayOutsideMaxExtent: true,
                        isBaseLayer: true,
                        yx : {'EPSG:2322' : true}
                 layer = new OpenLayers.Layer.WMS(
                        LAYERS: 'bla:bla',
                        format: "image/png",
                        opacity: 0.2,
                        isBaseLayer: false
                    var select = new OpenLayers.Layer.Vector("Selection", { styleMap: new OpenLayers.Style(OpenLayers.Feature.Vector.style["select"]) });

                map.addLayers([layer, tiled, select]);

                control = new OpenLayers.Control.GetFeature({ protocol: OpenLayers.Protocol.WFS.fromWMSLayer(layer) });
                control.events.register("featureselected", this, function (e) {
                control.events.register("featureunselected", this, function(e) { select.removeFeatures([e.feature]); });

                layer.mergeNewParams({'CQL_FILTER': "fid = ADRES_BINA.125063"});

                for (var j = 0; j < control.features.length; j++) {
                    var geom = control.features[j].geometry;

  • 1
    Your question is not clear to me. Do you have the address in your data? or do you wish to geocode and zoom to any arbitrary address? Dec 10, 2013 at 8:27
  • on geoserver i have all table for example country, town, street i search with feature name and and find feature ,select it and focus. That's all heron has query filter like that Dec 10, 2013 at 9:09

2 Answers 2


Try setting up your vector layer with a filter, strategy, and protocol. and event handler. I have not included any protocol code. The protocol will bind you wms layer to the vector layer, so to speak.


  strategies: [new OpenLayers.Strategy.Fixed()],

  filter = new OpenLayers.Filter.Comparison({
    type: OpenLayers.Filter.Comparison.EQUAL_TO,
    property: "fid",
    value: some value

    featureadded: function() {

then as the attribute changes in your code, set the filter and refresh the layer

  filter.value = some value;

  • i couldn't do that :/ how will i add these code. ? Dec 10, 2013 at 16:05
  • 1
    I am not sure what you could not do. Is you issue with setting up the vector layer with a filter, protocol, strategy etc, or are you unable to set the filter value?
    – Ralph Dell
    Dec 10, 2013 at 19:58

You can't search a WMS for a textual string, it's not part of the WMS standard. You will need to search some other service, perhaps a gazetteer, perhaps a WFS, and use the results of that service to give you a bounding box which you can use to define your WMS request.

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