[GIS] Openlayers getDataExtent not working

boundless-suiteopenlayers-2

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 
map.addLayers([osm,wms11]);

// 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();
            alert(bounds);
            map.zoomToExtent(bounds);});
            }
        }
    }
}); 

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!

Best Answer

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