How to zoom to wms layer after cql filter on Open layers

المشرف العام

Administrator
طاقم الإدارة
I created a layer that contains points and I added it to a map as WMS layer on 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; //var filter = "cité aïn-chock"; // 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 //mergeNewParams(filterParams); wfs_layer.mergeNewParams(filterParams); var bounds = new OpenLayers.Bounds bounds = wfs_layer.getExtent() //map.zoomToExtent (bounds); //var center = new OpenLayers.LonLat( wfs_layer.getExtent() ); //center.transform(new OpenLayers.Projection("EPSG:4326"), new OpenLayers.Projection("EPSG:900913")); //alert(center+','+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 ther 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'}); Thank you for helping me



أكثر...
 
أعلى