Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

Any help with this would be appreciated. I am projecting a WMS-layer on a map using OpenLayers and Geoserver. The next thing I want to do is to display info on any given feature in my WMS-layer in a popup whenever a user clicks it.

This is all working fine, but my problem is that whenever I click outside the WMS-layer, I get an empty popup. However, I only want a popup to appear when a user clicks an actual feature.

Does anyone know how to fix this? Thnx in advance!

share|improve this question
    
can you share your code to see what is wrong with it? –  Aragon Jan 22 '13 at 11:24
    
info = new OpenLayers.Control.WMSGetFeatureInfo({ url: 'http://../geoserver/cite/wms', title: 'Vraag informatie op over een melding door erop te klikken', queryVisible: true, eventListeners: { getfeatureinfo: function(event) { deletePopup(); popup = new OpenLayers.Popup.FramedCloud( "chicken", map.getLonLatFromPixel(event.xy), null, event.text, null, true ); map.addPopup(popup); } } }); map.addControl(info); info.activate(); –  Michiel Jan 22 '13 at 11:27
add comment

2 Answers

fixed it already!

I added this to my code (the stuff in bold):

...event) {deletePopup(); if (event.text.indexOf("") != -1) { popup = new OpenLayers...

(And an extra } after map.addPopup(popup); obviously.

share|improve this answer
add comment

Maybe is more intuitive to ask:

if (event.features.length != 0)

If you don't touch a feature, OpenLayers will set this parameter to 0, because the GeoServer response is "empty".

Regards

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.