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 apply a filter to one layer and works nice. I want to maximize the bounds where I applied the filter, like this:

// mapbounds = array(minx,miny,maxx,maxy)

activeLayer = new OpenLayers.Layer.WMS(
      layername, layerurl,
         width: map.size.w,
         srs: map.projection,
         layers: layername,
         height: map.size.h,
         styles: '',
         format: 'image/png',
         transparent: false

 // for example: conditions = 'igh > 5000 AND BBOX('the_geom,1,2,3,4)'    
         'cql_filter': conditions

bounds = new OpenLayers.Bounds(mapbounds[0],mapbounds[1],mapbounds[2],mapbounds[3]);


The filter works fine, but the zoom is restored too quickly after apply it. It's applied, but the layer restore to the initial view instantly.

What am I doing wrong?

Thanks in advance!

share|improve this question
as I said on the mailing list we need to see all the code – iant Feb 2 '11 at 21:56

you can use tileloaded or loadend event for firing zoomToExtent method."tileloaded", activeLayer, function() {
});"loadend", activeLayer, function() {


you can use setTimeout function to make it wait for 5 minute...

function sleep()
  setTimeout(wake, 5000); //wait five seconds then fire the wakeup function

function wakeup()
   map.zoomToExtent(bounds); //  now zoom to extent

i hope it helps you...

share|improve this answer

Applying a CQL_FILTER to a WMS layer won't change any bounds property's value. A WMS layer is just images. So what you can do is issue a WFS GetFeature request with the same filter in parallel, parse the response and calculate the bounds from the bounds of each feature. Needless to say that this will be terribly slow if your filter result returns more than a few hundred features.

share|improve this answer

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.