I am trying to develop a GIS application using GeoServer and OpenLayers. I want to get the bounds from GeoServer Native Bounding Box data of a layer instead of manually hard code:
var map;
var key = 0;
var fromNo = "";
var toNo = "";
var colorId = "";
var count = 0;
function init(){
format = 'image/png';
if(map)
map.destroy();
var bounds = new OpenLayers.Bounds(
8568700.4305088, 1677704.30921461,
9195694.68892519, 2070938.3484273
);
var options = {
controls: [],
maxExtent: bounds,
maxResolution: "auto",
projection: "EPSG:900913",
units: 'degrees',
minZoomLevel: 0, numZoomLevels:15,maxZoomLevel:15
};
var click_ap ;
var values = new Array();
map = new OpenLayers.Map('map', options);
$('.selectionTable tr').each(function() {
fromNo = $(this).closest("tr").find(".fromNo").val();
toNo = $(this).closest("tr").find(".toNo").val();
colorId = $(this).closest("tr").find(".colorSelect option:selected").val();
apZoomLevel1 = new OpenLayers.Layer.WMS(
"ap",
"http://localhost:8090/geoserver/scmapWithSelectColor/wms??request=getCapabilities ",
{'layers': 'scMapQuery',
viewparams: 'fromNo:'+fromNo+';toNo:'+toNo+';colorId:'+colorId+';',
'transparent': true,isbaselayer:false},{
singleTile: true,opacity: .5
}
);
values.push(apZoomLevel1);
});
click_ap = new OpenLayers.Control.WMSGetFeatureInfo({
url:'http://localhost:8090/geoserver/scmapWithSelectColor/wms',
title: 'Identify features by clicking',
layers: [apZoomLevel1],
queryVisible: true,
eventListeners: {
getfeatureinfo: function(event) {
if (ContentFilterAp(event.text,'hos').length>0){
//alert("localitieslevel3");
map.addPopup(new OpenLayers.Popup.FramedCloud(
"apZoomLevel1",
map.getLonLatFromPixel(event.xy),
null,
ContentFilterAp(event.text,'hos'),
null,
true
));}
}
}
});
gmap = new OpenLayers.Layer.Google
(
"Google Streets"
);
ghyb = new OpenLayers.Layer.Google
(
"Google Hybrid",
{type: google.maps.MapTypeId.HYBRID}
);
map.addControl(new OpenLayers.Control.Navigation());
map.addControl(new OpenLayers.Control.LayerSwitcher({'div':OpenLayers.Util.getElement('layerswitcher')}));
map.addLayers([gmap,ghyb]);
var length = values.length;
if(length > 0)
{
for(i=0;i<length;i++)
{
//debugger;
map.addLayers([values[i]]);
}
}
map.addControl(new OpenLayers.Control.PanZoomBar({
}));
map.addControl(new OpenLayers.Control.Navigation());
map.addControl(new OpenLayers.Control.Scale($('scale')));
map.addControl(new OpenLayers.Control.MousePosition({element: $('location')}));
map.zoomToExtent(bounds);
map.addControl(click_ap);
click_ap.activate();
map.events.register('zoomend', this, function (event) {
}); }
Actually above bounds are hard coded but actually apzoomlevel1 have native bounds how to get those one? actually those bounds useful in map.zoomToExtent(bounds);
based on that map zoom will change
GetCapabilities
request on the WMS service to get the Bounding box.