I would like to do the following:
1) While loading an OpenLayers map object get the lat/long Bounding Box of a WFS vector layer served from GeoServer. 2) Use the extent from the WFS vector layer to zoom so the entire layer is viewable.
This is the script I have now that uses the lat/longs from the WFS vector and then zooms. This script works fine. I have a javascript function where the map and controls are created in the onLoad of the html Body tag. At the end of the script I call the loadZoomTo() function which then calls this line of script;
function zoomOnLoad() {
this.map.setCenter(new OpenLayers.Bounds(-79.8961,41.1,-78.80809,42.2).getCenterLonLat(), 10);
}
In this script I have the lat/longs hard-coded but I need to be able to change these interactively depending on what option the user selects when he enters the application. If I remove the hard-coded lat/longs and try to replace them with something like this:
function zoomOnLoad() {
this.map.setCenter(new OpenLayers.Bounds(mLayers[a].getDataExtent()).getCenterLonLat(), 0);
}
it fails. I have also tried the event handler method as detailed here: OpenLayers, zoom to vector layer extent
but all I get is the html of the page with none of the OpenLayers stuff. No map, no controls etc..
Any suggestions would be appreciated.