[OpenLayers-Users] Get Feature Info in pop up from geoserver

Ivan Grcic ivan.grcic at geo-solutions.it
Mon May 9 12:22:41 EDT 2011


Hi Sukuchha,

please read inline below.

On Mon, May 9, 2011 at 11:13 AM, Sukuchha Shrestha <sukuchha at yahoo.de> wrote:
> Hi Ivan,
> This thing is making me mad. I have spent more than two days on this things
> still its not working. My display projection is mercator but my WMS layer
> from where i want to get info is in espg:4326.
> I am trying this in two ways:
> 1)
> info = new OpenLayers.Control.WMSGetFeatureInfo({
>             url: 'http://geoweb.hft-stuttgart.de:80/geoserver/wms',
>             title: 'Identify features by clicking',
>             layers: [wmslayer],
>             //hover:true,
>             queryVisible: true,
>             eventListeners: {
>                 getfeatureinfo: function(event) {
>
>                     map.addPopup(new OpenLayers.Popup.FramedCloud(
>                         "chicken",
>                         map.getLonLatFromPixel(event.xy),
>                         null,
>                         event.text,
>                         null,
>                         true
>                     ));
>                     //alert(event.text);
>
>                 }
>             }
>
>         });
>         map.addControl(info);
>         info.activate();
> There are point feautures in my WMS. WMS is congfigured in ESPG:4326 in my
> geoserver. When i click to a point, the point information is passed
> in projectionMercator or projection4326 ? I think this is where the problem
> lies ! To work correctly the point information should be passed in ESPG:
> 4326 but i dont see a parameter in OpenLayers.Control.WMSGetFeatureInfo
> where i can set this . I always get blank reponse !

Can you copy/paste the gfi request from the firebug?
OpenLayers.Control.WMSGetFeatureInfo should correctly include srs in
the request, so the geoserver should  reproject input geometry if its
not in the same srs as original data.

>
> 2) Geoserver way.
>  map.events.register('click', map, function (e) {
>                     //document.getElementById('nodelist').innerHTML =
> "Loading... please wait...";
>                     var params = {
>                         REQUEST: "GetFeatureInfo",
>                         EXCEPTIONS: "application/vnd.ogc.se_xml",
>                         BBOX:
> map.getExtent().transform(map.getProjectionObject(),projection4326).toBBOX(),
>                         X: e.xy.x,
>                         Y: e.xy.y,
>                         INFO_FORMAT: 'text/html',
>                         QUERY_LAYERS: 'test_postgis:addressv2b',
>                         FEATURE_COUNT: 50,
>                         Layers: 'test_postgis:addressv2b',
>                         Styles: '',
>                         WIDTH: map.size.w,
>                         HEIGHT: map.size.h,
>                         format: 'image/jpeg'};
>
> OpenLayers.loadURL("http://geoweb.hft-stuttgart.de:80/geoserver/wms",
> params, this, setHTML, setHTML);
>                     //OpenLayers.Event.stop(e);
>                 });
>
>
>             // sets the HTML provided into the nodelist element
>             function setHTML(response){
>
>             map.addPopup(new OpenLayers.Popup.FramedCloud(
>                         "chicken",
>                        map.getLonLatFromPixel(event.xy),
>
>                         null,
>                        response.responseText,
>                         null,
>                        true
>                    ));
>

In this case setHTML function doesnt have access to event object of
the click call back function: map.events.register('click', map,
function (e) { ...}
Moving  the setHTML  function inside  the call back function and
modifying event.xy -> e.xy should do the trick.

Regards,
Ivan

>
>
>
>                 //document.getElementById('nodelist').innerHTML =
> response.responseText;
>             };
>
> But this ones says, "event is not defined ".
> Please help me with this
> sukuchha
> ________________________________
> Von: Ivan Grcic <ivan.grcic at geo-solutions.it>
> An: Sukuchha Shrestha <sukuchha at yahoo.de>; geoserver-users
> <geoserver-users at lists.sourceforge.net>
> Gesendet: Freitag, den 6. Mai 2011, 19:12:50 Uhr
> Betreff: Re: [OpenLayers-Users] Get Feature Info in pop up from geoserver
>
> Hi,
>
> it seems that for some reason you are not getting any features back
> from you geoserver. (are you sure there are some features at requested
> point?)
>
> This can also happen due to several things, but most likely your layer
> is not configured with correct spatial reference system, so geoserver
> doesnt return any feature at requested point.
>
> Cheers,
> Ivan
>
> On Fri, May 6, 2011 at 5:59 PM, Sukuchha Shrestha <sukuchha at yahoo.de> wrote:
>> Hello ivan,
>> Thank you very much for pointing me towards the righ path. I tried to
>> apply
>> as shown in that html but but i ran into the problem again.
>> Somehow my pop is not returning the get feature info but empty. I tried to
>> see with firebug and i found that the geoserver is actually returning
>> something.
>> <html>
>>   <head>
>>     <title>Geoserver GetFeatureInfo output</title>
>>   </head>
>>   <style type="text/css">
>> table.featureInfo, table.featureInfo td, table.featureInfo th {
>> border:1px solid #ddd;
>> border-collapse:collapse;
>> margin:0;
>> padding:0;
>> font-size: 90%;
>> padding:.2em .1em;
>> }
>> table.featureInfo th {
>>    padding:.2em .2em;
>> font-weight:bold;
>> background:#eee;
>> }
>> table.featureInfo td{
>> background:#fff;
>> }
>> table.featureInfo tr.odd td{
>> background:#eee;
>> }
>> table.featureInfo caption{
>> text-align:left;
>> font-size:100%;
>> font-weight:bold;
>> text-transform:uppercase;
>> padding:.2em .2em;
>> }
>>   </style>
>>   <body>
>>
>>   </body>
>> </html>
>> I guess this is header template  that is there is geoserver. Ideally it
>> should come with content templete as well.
>> Any idea what is the problem here.
>> Thanks
>> Sukuchha
>> ________________________________
>> Von: Ivan Grcic <ivan.grcic at geo-solutions.it>
>> An: Sukuchha Shrestha <sukuchha at yahoo.de>
>> CC: users at openlayers.org
>> Gesendet: Freitag, den 6. Mai 2011, 11:02:29 Uhr
>> Betreff: Re: [OpenLayers-Users] Get Feature Info in pop up from geoserver
>>
>> Hi Sukuchha,
>>
>> You should use openlayers popup feature.
>>
>> This example is perfect for you :
>> http://openlayers.org/dev/examples/getfeatureinfo-popup.html
>>
>> Regards,
>> Ivan
>>
>> On Fri, May 6, 2011 at 10:49 AM, Sukuchha Shrestha <sukuchha at yahoo.de>
>> wrote:
>>> Hello nice people,
>>> i am trying to display get feature info of WMS layers coming from my
>>> geoserver. I do not have much experience with open layers and geoserver
>>> as
>>> well.
>>> This is what geoserver preview layers give to me:
>>> // support GetFeatureInfo
>>>                 map.events.register('click', map, function (e) {
>>>                     document.getElementById('nodelist').innerHTML =
>>> "Loading... please wait...";
>>>                     var params = {
>>>                         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[0].params.LAYERS,
>>>                         FEATURE_COUNT: 50,
>>>                         Layers: 'sf:bugsites',
>>>                         Styles: '',
>>>                         WIDTH: map.size.w,
>>>                         HEIGHT: map.size.h,
>>>                         format: format};
>>>
>>> OpenLayers.loadURL("http://localhost:8080/geoserver/wms", params, this,
>>> setHTML, setHTML);
>>>                     OpenLayers.Event.stop(e);
>>>                 });
>>>             }
>>>  function setHTML(response){
>>>                 document.getElementById('nodelist').innerHTML =
>>> response.responseText;
>>>             };
>>>
>>> But in my case, I want to display the getfeatureinfo not in a external
>>> div
>>> but on a openlayers right beside the where user have clicked. If, any one
>>> could provide me a working code to do this and explain in a coincise
>>> manner
>>> ??
>>> Sorry if this is too basic stuff for some people ! I am in class 1 of
>>> openlayers and geoserver :))
>>> Sukuchha
>>>
>>> _______________________________________________
>>> Users mailing list
>>> Users at lists.osgeo.org
>>> http://lists.osgeo.org/mailman/listinfo/openlayers-users
>>>
>>>
>>
>>
>>
>> --
>> -------------------------------------------------------
>> Ivan Grcic
>> GeoSolutions S.A.S.
>> Software Engineer
>>
>>
>> Via Poggio alle Viti 1187
>> 55054  Massarosa (LU)
>> Italy
>>
>> phone: +39 0584 962313
>> fax:      +39 0584 962313
>>
>> http://www.geo-solutions.it
>> http://geo-solutions.blogspot.com/
>> http://twitter.com/geosolutions_it
>> http://www.youtube.com/user/GeoSolutionsIT
>>
>> -------------------------------------------------------
>>
>
>
>
> --
> -------------------------------------------------------
> Ivan Grcic
> GeoSolutions S.A.S.
> Software Engineer
>
>
> Via Poggio alle Viti 1187
> 55054  Massarosa (LU)
> Italy
>
> phone: +39 0584 962313
> fax:      +39 0584 962313
>
> http://www.geo-solutions.it
> http://geo-solutions.blogspot.com/
> http://twitter.com/geosolutions_it
> http://www.youtube.com/user/GeoSolutionsIT
>
> -------------------------------------------------------
>



-- 
-------------------------------------------------------
Ivan Grcic
GeoSolutions S.A.S.
Software Engineer


Via Poggio alle Viti 1187
55054  Massarosa (LU)
Italy

phone: +39 0584 962313
fax:      +39 0584 962313

http://www.geo-solutions.it
http://geo-solutions.blogspot.com/
http://twitter.com/geosolutions_it
http://www.youtube.com/user/GeoSolutionsIT

-------------------------------------------------------


More information about the Users mailing list