I am using openlayers and Geoserver. I have created a base layer using OSM and then added wms layer topp:states. I want to show a world map and on that show US states. I have added onclick functionality to get feature info. However, when I click at any states, it gives incorrect state name or no result. This further worsens when I zoom in/zoom out or change the scale.Here is my code:
CSS:
#map {
position: relative;
height:1000px;
width:1400px;
float:left;
margin:0px ;
}
Script:
var bounds = new OpenLayers.Bounds(
-180,-90,0,90
);
format = 'image/png';
var options = {
controls: [],
maxExtent: bounds,
maxResolution: 0.22563114453125,
projection: "EPSG:4326",
units: 'degrees',
displayProjection: new OpenLayers.Projection("EPSG:4326")
};
map = new OpenLayers.Map('map', options);
layer = new OpenLayers.Layer.OSM("Base OpenStreet Map");
states = new OpenLayers.Layer.WMS(
"NA states", "http://localhost:8080/geoserver/wms",
{
layers: 'topp:states', styles: '', transparent: true, format: 'image/png'
},
{ isBaseLayer: false, singleTile: false,displayOutsideMaxExtent: true, ratio: 1,yx : {'EPSG:4326' : true} }
);
map.addLayers([layer,states]);
Code with call to getfeatureInfo:
map.events.register('click', map, function (e) {
document.getElementById('nodelist').innerHTML = "Loading... please wait...";
OpenLayers.Request.GET({url:"http://localhost:8080/geoserver/wms",params:{
REQUEST: "GetFeatureInfo",
EXCEPTIONS: "application/vnd.ogc.se_xml",
BBOX: bounds.toBBOX(),
SERVICE: "WMS",
INFO_FORMAT: 'text/html',
QUERY_LAYERS: [ map.layers[1].params.LAYERS],
FEATURE_COUNT: 50,
Layers: [map.layers[1].params.LAYERS],
WIDTH: map.size.w,
HEIGHT: map.size.h,
x: Math.floor(e.xy.x),
y: Math.floor(e.xy.y),
}, success:setHTML});
OpenLayers.Event.stop(e);
});
It may have to do with bounds or extents,but that's just my guess.