[OpenLayers-Users] Popup only on WMS layer object

Sveen Atle Frenvik (Geomatikk IKT) Atle.Frenvik.Sveen at geomatikk.no
Wed Aug 3 08:32:14 EDT 2011


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
	Users at lists.osgeo.org
	http://lists.osgeo.org/mailman/listinfo/openlayers-users



-- 
Atle Frenvik Sveen
Utvikler
Geomatikk IKT AS
tlf: 45 27 86 89
atle.frenvik.sveen at geomatikk.no
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/openlayers-users/attachments/20110803/df6da880/attachment.html


More information about the Users mailing list