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 
<table class="featureInfo"> if there are results). This can be done with 
someting like:




info = new OpenLayers.Control.WMSGetFeatureInfo({
                url: 'http://webgis.24gis.pl/geoserver/wms', 
                title: 'Identify features by clicking',
                queryVisible: true,
                infoFormat: 'text/html',
                maxFeatures: 1,
                eventListeners: {
                        getfeatureinfo: function(event) {

                                if (event.text.indexOf("<table 
class=\"featureInfo\">") != -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);


On 2011-08-03 13:22, michsred wrote: 

        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: 'http://webgis.24gis.pl/geoserver/wms', 
                        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: 
http://osgeo-org.1803224.n2.nabble.com/Popup-only-on-WMS-layer-object-tp6648352p6648352.html
        Sent from the OpenLayers Users mailing list archive at Nabble.com.
        _______________________________________________
        Users mailing list
        [email protected]
        http://lists.osgeo.org/mailman/listinfo/openlayers-users



-- 
Atle Frenvik Sveen
Utvikler
Geomatikk IKT AS
tlf: 45 27 86 89
[email protected]
_______________________________________________
Users mailing list
[email protected]
http://lists.osgeo.org/mailman/listinfo/openlayers-users

Reply via email to