I created a layer that contains points and I added it to a map as WMS layer in OpenLayers. I did a CQL filter and it works but I'd like to zoom to the selected point when I worked with getextent or getdataextent it doesn't zoom to the right place. It missed with a few Km. Here is my the code of filter:
function filterNom(){
var filterType ="cql";
var filter = document.getElementById('batima').value;
// by default, reset all filters
var filterParams = {cql_filter: null};
if (OpenLayers.String.trim(filter) != "") {
if (filterType == "cql")
filterParams["cql_filter"] = "batiment='"+filter+"'";
}
// merge the new filter definitions
wfs_layer.mergeNewParams(filterParams);
var bounds = new OpenLayers.Bounds
bounds = wfs_layer.getExtent()
map.setCenter(wfs_layer.getExtent(),18);
var center = map.getCenter();
center.transform(new OpenLayers.Projection("EPSG:4326"), new OpenLayers.Projection("EPSG:900913"));
alert(center.toString());
}
and here is the code to add the WMS layer:
wfs_layer = new OpenLayers.Layer.WMS("Patrimoines",
"http:// localhost/geoserver/cite/wms",
{layers: 'cite:patrimoine' , transparent: true },
{isBaseLayer: false, opacity: 1, singleTile: true, visibility: true,
projection: 'EPSG:900913'});