I have tried to send manual WMS GetFeatureInfo request to GeoServer with the parameter values X and Y (pixel values) taken from the map object of OpenLayers.
I have got the response with the wrong values which is not matched with the values I have seen in the GeoServer preview with the same long/lat.
The requested URL was:
geoserverUrl/wms?REQUEST=GetFeatureInfo&EXCEPTIONS=application/vnd.ogc.se_xml&BBOX=getextentValue&SERVICE=WMS&INFO_FORMAT=text/html&QUERY_LAYERS=xxxxx:atm&Layers=xxxxx:atm&WIDTH=mapwidth&HEIGHT=mapheight&format=image/jpeg&styles=&srs=EPSG:4326&version=1.1.1&x=eventxvalue&y=eventyvalue";
I have referred with these posts also: Can Geoserver return the raster value of a lat/lon point.
Is there any possible way to give the clicked long/lat values given instead of X and Y pixel values in a GeoServer WMS GetFeatureInfo request?
or
What are the factors which are to be clear when making this request manually. More particular width, height and the BBOX values?
In client side I have made an AJAX call:
map.events.register("click",this, function(e){
var clickedLatLong =map.getLonLatFromViewPortPx(e.xy);
var clickedPixel = map.getPixelFromLonLat(clickedLatLong);
//alert(clickedLatLong);
//alert(map.size);
if(!map.getMaxExtent().containsLonLat(clickedLatLong)) {
return;
}else{
alert(clickedPixel);
var bbox = map.getExtent();
alert(bbox);
$.ajax({
type: 'GET',
url: 'getMultiLayersValue.html',
dataType: 'html',
data:{long:clickedPixel.e.x,lat:clickedPixel.e.y},
success : function(result){
alert(result);
$("#DisplayResponse").html(result);
$("#DisplayResponse").dialog( "open" );
},
complete:function(xhr, txtStatus){
},
error: function(xhr, error){
showLoadingMaskDialog(false,loadingText);
alert("Taking More Time to Respond\n Please Try Later or Contact System Administrator");
}
});//ajax
}
In server side I have made this URL request:
"localhost:8080/geoserver/wms?REQUEST=GetFeatureInfo&EXCEPTIONS=application/vnd.ogc.se_xml&BBOX=getextentValue&SERVICE=WMS&INFO_FORMAT=text/html&QUERY_LAYERS=xxxxx:atm&Layers=xxxxx:atm&WIDTH=mapwidth&HEIGHT=mapheight&format=image/jpeg&styles=&srs=EPSG:4326&version=1.1.1&x=eventxvalue&y=eventyvalue";
Eventually no error messages were found only I got the wrong values for my clicked long/lat. May be the values of pixel getting wrong but I unable to find the solutions.
var clickedLatLong =map.getLonLatFromViewPortPx(e.xy);
var clickedPixel = map.getPixelFromLonLat(clickedLatLong);
have some responsibility