Discussion:
[OpenLayers-Users] GetFeatureInfo
eoinyp
2009-09-23 14:38:02 UTC
Permalink
Hi, Im trying to use extract the info on a feature clicked on and display it
below the map in HTML.
I know its a very common task, Ive been following the examples on this list.
Im nearly there except for one small thing - nothing displays for me, i.e no
feature info is returned. Im not sure that it is extracting the correct
info. How does it know which attributes of the feature clicked on to return?
Thanks.
Eoinyp.

Here are some of my code extracts.

//setup a WMS of the Lakes in Ireland:
var Lakes = new OpenLayers.Layer.WMS(
"Irish Lakes", "http://ncg.nuim.ie/geoserver/wms",
{
layers: 'Lakes_all_2005',
styles: '',
srs: 'EPSG:29900',
format: format,
tiled: 'true',
transparent: "true",
},
{buffer: 1}
);



// support GetFeatureInfo
map.events.register('click', map, function (e) {
document.getElementById('nodelist').innerHTML =
"Loading... please wait...";

var url = Lakes.getFullRequestString(

{REQUEST: "GetFeatureInfo",
EXCEPTIONS: "application/vnd.ogc.se_xml",
BBOX: map.getExtent().toBBOX(),
X: e.xy.x,
Y: e.xy.y,
INFO_FORMAT: 'text/html',
QUERY_LAYERS: map.layers[5].params.LAYERS,
//Lakes are in layer 5
FEATURE_COUNT: 50,
WIDTH: map.size.w,
HEIGHT: map.size.h}
);


//put in an alert for debugging:
alert("url :"+url); //the message returned by this alert is below.


OpenLayers.loadURL(url,'',this, setHTML);

OpenLayers.Event.stop(e);
});

//function to set the HTML

function setHTML(response) {
//debugging
alert("setting html response to "+response.responseText);
//the message returned by this alert is blank, i.e. response.responseText
has no value.

OpenLayers.Util.getElement('nodeList').innerHTML =
response.responseText;}



//The message returned by the first alert is as follows:

http://ncg.nuim.ie/geoserver/wms?LAYERS=Lakes_all_2005&STYLES=&SRS=EPSG%3A900913&FORMAT=image%2Fpng&TILED=true&TRANSPARENT=true&SERVICE=WMS&VERSION=1.1.1&REQUEST=GetFeatureInfo&EXCEPTIONS=application%2Fvnd.ogc.se_xml&BBOX=-1463708.980937%2C6686200.264297%2C-485315.019062%2C7419995.735703&X=351&Y=284&INFO_FORMAT=text%2Fhtml&QUERY_LAYERS=Lakes_all_2005&FEATURE_COUNT=50&WIDTH=800&HEIGHT=600
--
View this message in context: http://n2.nabble.com/GetFeatureInfo-tp3700058p3700058.html
Sent from the OpenLayers Users mailing list archive at Nabble.com.
eoinyp
2009-09-23 14:42:21 UTC
Permalink
Sorry, the last part of my question read incorrectly: I know that it is
extracting the information on the features where I click - the URL returned
by the alert in my code shows this. Rather my question should read, how can
I display a limited set of the attributes shown in the link above in the
HTML below the map.
Thankyou

Eoinyp
--
View this message in context: http://n2.nabble.com/GetFeatureInfo-tp3700058p3700090.html
Sent from the OpenLayers Users mailing list archive at Nabble.com.
Lehtonen, Mika
2009-09-23 16:23:01 UTC
Permalink
Hi Eoinyp,
at least you can request GetFeatureInfo with different format [1] (GML)
and parse out the data you would like to publish. Or you can create your
own freemarker template for your Geoserver [2].
How do these options sound like? Maybe there are some easier "filters",
I don't know about..

- mika -

[1] http://ncg.nuim.ie/geoserver/wms?REQUEST=GetCapabilities
....
<GetFeatureInfo>
<Format>text/plain</Format>
<Format>text/html</Format>
<Format>application/vnd.ogc.gml</Format>
.....

[2] http://geoserver.org/display/GEOSDOC/Freemarker+templates
Post by eoinyp
Sorry, the last part of my question read incorrectly: I know that it is
extracting the information on the features where I click - the URL returned
by the alert in my code shows this. Rather my question should read, how can
I display a limited set of the attributes shown in the link above in the
HTML below the map.
Thankyou
Eoinyp
regioGIS
2009-09-24 09:25:21 UTC
Permalink
Hi,

Instead of doing the GetFeatureInfo request yourself, you can use the
OpenLayers.Control.WMSGetFeatureInfo, which additionally also does the
result parsing for you. You can then easily access all the returned features
from an array.

Cheers,
Post by eoinyp
Sorry, the last part of my question read incorrectly: I know that it is
extracting the information on the features where I click - the URL
returned by the alert in my code shows this. Rather my question should
read, how can I display a limited set of the attributes shown in the link
above in the HTML below the map.
Thankyou
Eoinyp
--
View this message in context: http://n2.nabble.com/GetFeatureInfo-tp3700058p3705071.html
Sent from the OpenLayers Users mailing list archive at Nabble.com.
eoinyp
2009-10-14 16:16:47 UTC
Permalink
Thanks for your help on this guys, regioGIS, I am trying to follow your tip
(quoted below), as it seems best for what I want to do. I am stuck on the
very first hurdle. Looking at the example at
http://www.openlayers.org/dev/examples/getfeatureinfo-control.html
this is exactly what I want to do - Click on the lake, view it associated
information.
I have coppied this example word for word and replaced the tasmania layers
in the example with my own layer. - No problems. But - when I click on my
layer (Irish_Counties) the information associated with the layer does not
display. Nothing happens. The system just seems to hang.
My attempt is at:
http://www.eoinmaca.com/maps/OpenLayers/getfeatureinfo-controlEXAMPLE.html

Any help on this would be greatly appreciated.
Many thanks,

Eoin.
Post by regioGIS
Instead of doing the GetFeatureInfo request yourself, you can use the
OpenLayers.Control.WMSGetFeatureInfo, which additionally also does the
result parsing for you. You can then easily access all the returned
features from an array.
--
View this message in context: http://n2.nabble.com/GetFeatureInfo-tp3700058p3823841.html
Sent from the OpenLayers Users mailing list archive at Nabble.com.
regioGIS
2009-10-15 09:44:40 UTC
Permalink
Hi,

2 things here :

1. I would use another format as html/text. I had some problems too to get
it parsed correctly.
So I added in the infoCtl this property :
var infoCtl = new OpenLayers.Control.WMSGetFeatureInfo({
title: ....
...
infoFormat: 'application/vnd.ogc.wms_xml'
});
2. I think you might have a problem with not having your proxy defined ....
not sure about this a 100% anymore, but I think this type of request is
always considered as a cross-domain request, and hence needs a proxy
defined.

best regards,
Post by eoinyp
Thanks for your help on this guys, regioGIS, I am trying to follow your
tip (quoted below), as it seems best for what I want to do. I am stuck on
the very first hurdle. Looking at the example at
http://www.openlayers.org/dev/examples/getfeatureinfo-control.html
...
--
View this message in context: http://n2.nabble.com/GetFeatureInfo-tp3700058p3828263.html
Sent from the OpenLayers Users mailing list archive at Nabble.com.
Continue reading on narkive:
Loading...