0

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 pop up 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 pop up. However, I only want a pop up to appear when a user clicks an actual feature.

Does anyone know how to fix this?

Code:

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();
2
  • can you share your code to see what is wrong with it?
    – urcm
    Jan 22, 2013 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, 2013 at 11:27

2 Answers 2

1

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.

0

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".

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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