-3

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(
                    "bla",
                    "http://bla.com:8080/geoserver/Kaski/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(
                    "Bina",
                    "http://bla.com:8080/geoserver/bla/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) {
                    alert(e.feature.fid);
                    select.addFeatures([e.feature]);
                });
                control.events.register("featureunselected", this, function(e) { select.removeFeatures([e.feature]); });

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

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

                map.zoomToExtent(bounds);
            }
2
  • 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 '13 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 '13 at 9:09
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.

Possibly;

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

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

  vector.events.on({
    featureadded: function() {
    map.zoomToExtent(vector.getDataExtent());
  });

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

  filter.value = some value;

  vector.refresh();
2
  • i couldn't do that :/ how will i add these code. ? Dec 10 '13 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 '13 at 19:58
2

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.