<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    
  </head>
  <body bgcolor="#ffffff" text="#000000">
    <pre wrap="">This is a bit tricky, as the wms server sends a response independent of wether it found any features or not.

A simple solution could be to check the response text for a string you know is only present if there are indeed results. (ie. geoserver adds 
<code class="wrappedText focusRow" role="listitem">&lt;table class="featureInfo"&gt; if there are results). This can be done with someting like:


</code>

info = new OpenLayers.Control.WMSGetFeatureInfo({
                url: '<a class="moz-txt-link-freetext" href="http://webgis.24gis.pl/geoserver/wms">http://webgis.24gis.pl/geoserver/wms</a>', 
                title: 'Identify features by clicking',
                queryVisible: true,
                infoFormat: 'text/html',
                maxFeatures: 1,
                eventListeners: {
                        getfeatureinfo: function(event) {

                                if (event.text.indexOf("&lt;table class=\"featureInfo\"&gt;") != -1){
                                        popup = new OpenLayers.Popup.FramedCloud(
                                                "chicken", 
                                                map.getLonLatFromPixel(event.xy),
                                                null,
                                                event.text,
                                                null,
                                                true
                                        ), {
                                                autoSize: false,
                                                maxSize: new OpenLayers.Size(5,5)
                                        };
                                        map.addPopup(popup);
                                }
                        }
                }
        });
        map.addControl(info);</pre>
    <br>
    <br>
    On 2011-08-03 13:22, michsred wrote:
    <blockquote cite="mid:1312370523686-6648352.post@n2.nabble.com"
      type="cite">
      <pre wrap="">Hi list,

is it possible to construct GetFeatureInfo machanism with popup which will
be active only on objects (points, lines, polygons) from WMS layers. I
already have popups working on my whole map. When I click outside of object
e.g polygon the opened popup is empty. I would like to have popups which
apear only on objects (or more precisely, only on places where
GetFeatureInfo information is present).

This is GetFeatureInfo code which I use:

info = new OpenLayers.Control.WMSGetFeatureInfo({
                url: '<a class="moz-txt-link-freetext" href="http://webgis.24gis.pl/geoserver/wms">http://webgis.24gis.pl/geoserver/wms</a>', 
                title: 'Identify features by clicking',
                queryVisible: true,
                infoFormat: 'text/html',
                maxFeatures: 1,
                eventListeners: {
                        getfeatureinfo: function(event) {
                                popup = new OpenLayers.Popup.FramedCloud(
                                        "chicken", 
                                        map.getLonLatFromPixel(event.xy),
                                        null,
                                        event.text,
                                        null,
                                        true
                                ), {
                                        autoSize: false,
                                        maxSize: new OpenLayers.Size(5,5)
                                };
                                map.addPopup(popup);
                        }
                }
        });
        map.addControl(info);


Thank you in advance for any sugestion!

Michal

--
View this message in context: <a class="moz-txt-link-freetext" href="http://osgeo-org.1803224.n2.nabble.com/Popup-only-on-WMS-layer-object-tp6648352p6648352.html">http://osgeo-org.1803224.n2.nabble.com/Popup-only-on-WMS-layer-object-tp6648352p6648352.html</a>
Sent from the OpenLayers Users mailing list archive at Nabble.com.
_______________________________________________
Users mailing list
<a class="moz-txt-link-abbreviated" href="mailto:Users@lists.osgeo.org">Users@lists.osgeo.org</a>
<a class="moz-txt-link-freetext" href="http://lists.osgeo.org/mailman/listinfo/openlayers-users">http://lists.osgeo.org/mailman/listinfo/openlayers-users</a>
</pre>
    </blockquote>
    <br>
    <br>
    <pre class="moz-signature" cols="72">-- 
Atle Frenvik Sveen
Utvikler
Geomatikk IKT AS
tlf: 45 27 86 89
<a class="moz-txt-link-abbreviated" href="mailto:atle.frenvik.sveen@geomatikk.no">atle.frenvik.sveen@geomatikk.no</a></pre>
  </body>
</html>