I set up a WMS with QGIS SERVER. I am querying it via a web app based on OpenLayers.
Everytime I click on my map, I send a GetFeatureInfo to a specific layer passing the coordinates where I clicked, and the response is rendered in a popup. So far so good.
The problem is if I click where there's no layer's feature in the map, I'd like no popup to show up, but instead I get an "empty-table-response" from the WMS which is in turn rendered in my popup, and this is annoying.
Here is an example of a request with some interesting data:
And here is one with empty data which I don't want to display in the popup:
This is how I am requesting the data in OL (only the relevant part):
function getInfoUrl(evt, view, lyr) {
var coordinate = evt.coordinate;
var url = CORS_PREFIX;
var viewResolution = /** @type {number} */ (view.getResolution());
if (lyr.get('type') != 'base') {
var visible = lyr.getVisible();
if (visible) {
url += lyr.get('source').getGetFeatureInfoUrl(evt.coordinate, viewResolution, 'EPSG:3857', {
'INFO_FORMAT': 'text/xml'
});
return url;
}
}
}
map.on('singleclick', function(evt) {
// display info in fancyAlert
for (let i = 0; i < ol_layers.length; ++i) {
let layer = ol_layers[i];
let text = getInfoUrl(evt, view, layer);
if (text) {
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
fancyAlert(this.responseText, 'info', 'Layer Info');
}
};
xhttp.open("GET", text, true);
xhttp.send();
}
}
})
How should I avoid the second response to show up? I thought a request to an empty feature area should trigger no response or at least a WMS exception. Maybe this is not a standard but it's what I was used to.