I have a WMS layer and want use zoomToExtent after CQL filter. So I get the layer BBOX from the GeoServer WMS using a GetCapabilities request.

wms = new OpenLayers.Format.WMSCapabilities();
  success: function(e){
    var response = wms.read(e.responseText);
    var capability = response.capability;
    for (var i=0, len=capability.layers.length; i<len; i+=1) { 
      var layerObj = capability.layers[i]; 
      if (layerObj.name === 'filedata') { 

But zoomToExtent doesn't work with lon lat, so how to get the BBOX in meters?

My map showed in epsg900913.

  • The answer is the same as your previous question - Zooming the map after filter WMS doesn't work the way that you seem to think. – Ian Turton May 21 '12 at 7:47
  • in last time im ask this question uncorrectly. But today i see project when its worc fine. – Kliver Max May 21 '12 at 8:18

you should use transform method for getting your result in meters.

OpenLayers.Projection.transform = function( point,
    dest    )

Transform a point coordinate from one projection to another. Note that the input point is transformed in place.


point {{OpenLayers.Geometry.Point> | Object} An object with x and y properties
representing coordinates in those dimensions.

sourceProj {OpenLayers.Projection} Source map coordinate system

destProj {OpenLayers.Projection} Destination map coordinate system

Example :

    var lonlat = new OpenLayers.LonLat(-3.57138, 39.8384);
    lonlat.transform(map.displayProjection, map.baseLayer.projection);
    map.setCenter(lonlat, 5);

i hope it helps you...

  • Strange thing. i get correct bbox in lon lat. After transform i get meters bbox its correct too. But when use zoomToExtent nothing heppens. Im add Controls.MousePosition and mouse show that my map out of extent which i get. Whats wrong? – Kliver Max May 21 '12 at 8:16
  • And another question if i have only polygons im must use setCenter()? – Kliver Max May 21 '12 at 8:21
  • try to get bobunding box center lon-lat. example: map.getExtent().getCenterLonLat()...then set it to center... – Aragon May 21 '12 at 8:30
  • transform(projection,displayProjection) dont working. Try convert lonlat in meters but its not heppening. – Kliver Max May 21 '12 at 10:03
  • can you share your error you have met? in normal situation it works very well – Aragon May 21 '12 at 10:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.