[GIS] How to get BBOX from WMS GetCapabilities response

geoservergetcapabilitiesopenlayers-2wms

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();
OpenLayers.Request.GET({
  url:"http://localhost:8080/geoserver/wms/filedata?request=GetCapabilities",
  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') { 
        map.zoomToExtent(OpenLayers.Bounds.fromArray(layerObj.llbbox)); 
        break; 
      } 
    }
  }
});

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

My map showed in epsg900913.

Best Answer

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

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

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

Parameters

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...

Related Question