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 WMS map, after applying CQL filter to layer how can I zoom map to see filter result?


Here is my code what I'm trying to do

var layerArray = map.layers;
var someLayer;

for (var i = 0; i < layerArray.length; i++) {
    if (layerArray[i].name == "myLayer"){
        someLayer = layerArray[i];

    "CQL_FILTER": celIDCondition /* (CID =1351 and LAC = 401) */

// instead of somelayer.maxExtend I want to extent map acording to CQL_FILTER result
share|improve this question
it seems that you need to expand this question to give us a better idea about what you are trying to do. Maybe you could post the code you are using so far? – iant May 18 '12 at 7:27
I updated my question Thanks – Iliaka May 18 '12 at 7:42
up vote 0 down vote accepted

if you just have a point then you can use something like:

     new OpenLayers.LonLat(longitude,latitude),

You can see a whole application which demonstrates this process at


You can't do what you want directly I'm afraid. The bounds of a WMS layer are defined in the request URL so the requested image will always be the same as the OpenLayers.Map object it is in (otherwise there would be edges and uncoloured in bits in the map).

The only way you will be able to do this is to make a WFS request (so that you ask for the actual data instead of a picture of the data) and then calculate the bounds of the returned object and zoom to that or calculate the centroid of the object and set a zoomlevel and center the map on that point.

share|improve this answer
no I have something like this someLayer.mergeNewParams({ "CQL_FILTER": celIDCondition }); – Iliaka May 17 '12 at 14:22

you can try:

var dataExtent = vectors.getDataExtent();




vectors is the layer which you add features from CQL_Filter.

you can try it here with firebug writing this to console:



var fixWMSLayerExtent = function(layer)
var readr = new
{ record: 'Layer'},
{name: 'name', mapping: 'Name'}
,{name: 'minx', mapping: 'LatLonBoundingBox > @minx'}
,{name: 'miny', mapping: 'LatLonBoundingBox > @miny'}
,{name: 'maxx', mapping: 'LatLonBoundingBox > @maxx'}
,{name: 'maxy', mapping: 'LatLonBoundingBox > @maxy'}

var myStore = new{
url : "/MapProxy?url=" + layer.url +'&request=GetCapabilities' ,
reader : readr
myStore.load({'layer' : layer, callback: function(r, options, success)
var rindex = this.find('name',, 0, true, true);
var rec = this.getAt(rindex);
layer.maxExtent = new OpenLayers.Bounds(,,,;
} });

the code is from Sergey Malgin...

i hope it helps you...

share|improve this answer
it takes me to the center of worlds map. when I alert dataExtend it gives undefined. my layer is wms layer not vector layer. Thanks – Iliaka May 17 '12 at 14:17
ok. so you directly use wms layer... there is a solution for this... i have updated my answer... – Aragon May 17 '12 at 14:21
seems to be good solution but I am not using Ext – Iliaka May 18 '12 at 7:08

If i read your code (and comments) correctly, i assume that "someLayer" is a WMS-layer, is this correct?

If so, getting the maxExtent is a bit problematic, as wms does not support this. If your WMS server offers the layer as WFS in addition to WMS, you could do a WFS request to the server, using the same filter as your WMS request, and get the extent from the features returned from the WFS request.

I could try to sketch an outline for the code doing this, but would like to get a confirmation that your someLayer is indeed a WMS layer.

share|improve this answer
Yes someLayer is WMS layer – Iliaka May 18 '12 at 9:12

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.