I've got a webmap showing data coming from a Geoserver instance. With better.WMS.js I made it possible to display popups.
Everything works nice except that the map shows popups too where there is no feature selected.
The code is hosted on GitHub. I'll try to put a working map online though one may see the problem clearly. The map shouldn't display a popup window when no feature is selected.
Does anyone has an idea how to fix that?
Best Answer
You can switch to infoformat=application/json so you will get a json response from Geoserver. Then just check how many features are returned and if features.length>0 is true show the popup otherwise not. For this solution you will have to create a table from the json-response. You could do something like that:
set infoformat in your L.TileLayer.BetterWMS.js:
// Create a function that will return a table from a json response:
and use this function while setting the content of the popup:
Screenshot from my working example with json response:
EDIT1: added two gists:
html-part: https://gist.github.com/anonymous/aa86f117f1342179f2e3
js-part: https://gist.github.com/anonymous/f6e7dc3d4eff9e0ed62b