I am following this tutorial http://workshops.boundlessgeo.com/tutorial-wordmap/ on the web about using setting up sql view on geoserver. I have set up my sql view correctly and have the javasctipt part working. When I enter a location in the textbox and press enter, the map will only display features of that particular location. However, I would like to go further so that my map can also zoom into the features of that location.

This is my code:

// Start with map of startWord
wms11.mergeNewParams({viewparams: "word:"+startWord});

//Add all layers to the map 

// Text field component. On 'enter' update the WMS URL
var textField = new Ext.form.TextField({
    value: startWord,
    listeners: {
    specialkey: function(fld, e) {
        // Only update the map when the user hits 'enter'
        if (e.getKey() == e.ENTER) {
            wms11.mergeNewParams({viewparams: "word:"+fld.getValue()});
            var bounds = wms11.getDataExtent();

The map was zoomed into an incorrect area and the alert(bounds) shows the bounds is undefined. What is going wrong here?

Thanks in advance!

1 Answer 1


It seems a misunderstanding on your side.

You are requesting an extent on a WMS by making a call to getDataExtent() The problem here is a WMS is raster layer where you don't have any extent information (only possible with features coming from a vector layer)

When you look in the API by searching the word getDataExtent you only see a reference to vector layers

getDataExtent in API

It seems that the getDataExtent is exposed in all layers (I've done a test with another raster type, WMTS) although not useful in all cases

  • Thanks. What would you recommend me to do for getting the data extent for a WMS layer?
    – K Hsueh
    Oct 31, 2013 at 1:55
  • You will need to make a WMS getCapabilities call (with OpenLayers.Request.GET), parse the result (with OpenLayers.Format.WMSCapabilities) to get the extent for the entire layer you want and after, you will be able to zoom
    – ThomasG77
    Oct 31, 2013 at 2:05
  • var bounds = OpenLayers.Bounds.fromArray(layerObj.llbbox); bounds.transform(proj4326, proj900913); map.zoomToExtent(bounds);
    – K Hsueh
    Dec 12, 2013 at 0:15
  • layerObj.llbbox is coming undefined
    – prem30488
    Sep 29, 2014 at 5:54
  • is there any workaround?
    – prem30488
    Sep 29, 2014 at 5:54

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.