Yes, see this answer: https://gis.stackexchange.com/a/211562/3399
This is the JavaScript implementation:
var parameters = {
service: 'WMS',
version: '1.1.1',
request: 'GetFeatureInfo',
layers: currentLayer,
query_layers: currentLayer,
feature_count: 10,
info_format: 'text/javascript',
format_options: 'callback:handleJson',
SrsName: 'EPSG:4326',
width: 101,
height: 101,
x: 50,
y: 50,
bbox: (lng - 0.1) + ',' + (lat - 0.1) + ',' + (lng + 0.1) + ',' + (lat + 0.1)
}
var url = owsurl + L.Util.getParamString(parameters)
$.ajax({
url: owsurl + L.Util.getParamString(parameters),
dataType: 'jsonp',
success: function (data) {
handleJson(data)
}
})
Basically, you use the lat, lon to create a bounding box, and select the values in the middle of it. You can return JSON, which you can eat up with your code.
You are making a GetFeatureInfo
request to a WMS service, the WMS is required by the standard to return information about the point you have clicked on. If there is more than one feature at the point then it may return information about all the features (up to featureCount
) that are there.
You seem to be asking for information about a raster so the request returns the value of the pixel that is at the point you have clicked on. Since you seem not to have many layers there you will only get back one pixel's value regardless of how high you set featureCount
.
If you are trying to fetch an area of the raster then you probably want to look at using a Web Coverage Service (WCS) request.
Best Answer
Update The 'hack' given below is necessary only for Geoserver versions 2.2.x and below. With version 2.3.0 and upwards, Geoserver can return JSON for WMS GetFeatureInfo request natively.
End of Update
There is an open feature request for this on geoserver's bug tracker.
Using custom GetFeatureInfo Templates, it is possible to generate a Json response from Geoserver.
You can follow these steps:
1]Go to the following folder
2] Create 3 empty text files with the following names: header.ftl, content.ftl & footer.ftl
3] Open the content.ftl file, and copy the following free-marker code:
4] Save the file and now make the WMS getFeatureInfo request. You'll see that the response is in JSON.
Note: You need to remember that this will wrap the numeric values in inverted commas as a string. Hence you might have to take care of it in the client code.