[OpenLayers-Users] Nodelist Info / GetFeatureInfo not working

Roald de Wit list at rdewit.net
Fri May 14 05:15:44 EDT 2010


Hi Pascal,

Are you sure your index.html is on server 'myownhomepage.xyz' and the 
same port? If so, you should be able to reference your geoserver with 
'/geoserver/wms'. If not, you need to use a proxy script or make sure 
that they are all on the same server and port.

Regards, Roald

On 11/05/10 05:14, boxplot wrote:
> Hi Roald,
>
> I made a complete new setup and found out that the enconding of one 
> file was not the right one. Now I can use the GS example anywhere on 
> my site and it works. But when I try to copy the code in my index.html 
> it's not working anymore (the map is loading but after a click there 
> is no request). So here is my code:
>
> index.html
>> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
>> "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
>>
>> <html xmlns="http://www.w3.org/1999/xhtml">
>>
>> <head>
>> <title>Map</title>
>> <link rel="stylesheet" href="style.css" type="text/css" />
>>
>> <script 
>> src="http://maps.google.com/maps?file=api&amp;v=2&amp;key=[Google 
>> <http://maps.google.com/maps?file=api&amp;v=2&amp;key=[Google> API 
>> Key]"></script>
>> <script src="OL/OpenLayers.js"></script>
>> <script src="javascript/karte2.js" type="text/javascript"></script>
>> </head>
>>
>> <body onload="init()">
>>
>> <div id="header">
>> <div id="ueberschrift"><h2>Map</h2></div>
>> <p id="subtitle">Map</p>
>> </div>
>>
>> <div id="inhalt">
>>
>> <div id="map" class="smallmap"></div>
>>
>> <div id="seitenleiste">
>> </div>
>>
>> <div id="nodelist">
>> <em>Click on the map to get feature info</em>
>> </div>
>> </div>
>> </body>
>> </html>
>
> Karte2.js
>> function init(){
>>
>> var options = {
>> controls: [],
>> };
>>
>> var map = new OpenLayers.Map('map', options);
>>
>> var gphy = new OpenLayers.Layer.Google(
>> "Google Physical",
>> {type: G_PHYSICAL_MAP}
>> );
>> var gmap = new OpenLayers.Layer.Google(
>> "Google Streets",
>> {numZoomLevels: 20}
>> );
>> var ghyb = new OpenLayers.Layer.Google(
>> "Google Hybrid",
>> {type: G_HYBRID_MAP, numZoomLevels: 20}
>> );
>> var satellite = new OpenLayers.Layer.Google(
>> "Google Satellite",
>> {type: G_SATELLITE_MAP}
>> );
>> var wms = new OpenLayers.Layer.WMS(
>> "My Map",
>> "http://myownhomepage.xyz/geoserver/wms",
>> {
>> srs: 'EPSG:4326',
>> layers: 'Map2:Layer',
>> transparent: 'TRUE'
>> },
>> {
>> 'reproject': true
>> }
>> );
>>
>> map.addLayers([satellite, wms, gphy, gmap, ghyb]);
>> map.setCenter(new OpenLayers.LonLat(12.5000,47.5000), 15);
>>
>> map.addControl(new OpenLayers.Control.LayerSwitcher() );
>> map.addControl(new OpenLayers.Control.Navigation());
>> map.addControl(new OpenLayers.Control.MousePosition({element: 
>> $('location')}));
>> map.addControl(new OpenLayers.Control.Permalink('permalink'));
>> map.addControl(new OpenLayers.Control.PanZoomBar({
>> position: new OpenLayers.Pixel(2, 15)
>> }));
>>
>> 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,
>> Srs: 'EPSG:4326',
>> Layers: 'Map2:Layer',
>> Styles: '',
>> WIDTH: map.size.w,
>> HEIGHT: map.size.h,
>> format: format};
>> OpenLayers.loadURL("http://myownhomepage.xyz/geoserver/wms", params, 
>> this, setHTML, setHTML);
>> OpenLayers.Event.stop(e);
>> });
>> }
>> function setHTML(response){
>> document.getElementById('nodelist').innerHTML = response.responseText;
>> };
>
> It is strange now but there is no request in Firebug. When I click on 
> the map the text switches to "Loading please wait" and that's it. 
> Maybe the problem is because of the different layers?
>
> Thank you very much for your help!
>
> Pascal
>
>
> Am 10.05.2010 um 00:06 schrieb Roald de Wit:
>
>> Hi Pascal,
>>
>> You should pretty much always get at least *something* back: either 
>> an error or an empty reponse (FireBug would tell you). Have you 
>> really got ":80" in your settings like below?
>>
>>    OpenLayers.loadURL("http://myownhomepage.xyz:80/geoserver/wms", 
>> params, this, setHTML, setHTML);
>>
>> If your Tomcat runs on port 80 then you can leave out the port 
>> number. That might do the trick (and yes, it would then have been a 
>> proxy issue). Like this:
>>
>>    OpenLayers.loadURL("http://myownhomepage.xyz/geoserver/wms 
>> <http://myownhomepage.xyz:80/geoserver/wms>", params, this, setHTML, 
>> setHTML);
>>
>> And since your OL is on the same server as your GS, you could even do 
>> this:
>>
>>    OpenLayers.loadURL("/geoserver/wms 
>> <http://myownhomepage.xyz:80/geoserver/wms>", params, this, setHTML, 
>> setHTML);
>>
>> And to deal with errors in your AJAX request, why not use a separate 
>> function like this:
>>
>>    OpenLayers.loadURL("/geoserver/wms 
>> <http://myownhomepage.xyz:80/geoserver/wms>", params, this, setHTML, 
>> *onAjaxError*);
>>
>> Regards, Roald
>>
>> On 10/05/10 05:45, boxplot wrote:
>>> Hi,
>>>
>>> maybe a made a small progress. As I have written in my last mail I 
>>> get no response when using GetFeatureInfo (I do get a response when 
>>> using the GeoServer OpenLayers example which I can access through 
>>> "Layer Preview" => see code below). So I copied both requests 
>>> directly into my browser and both got a response:
>>>
>>>> http://myownhomepage.xyz/geoserver/wms?REQUEST=GetFeatureInfo&EXCEPTIONS=application%2Fvnd.ogc.se_xml&BBOX=12.327023%2C47.673%2C12.362977%2C47.777&X=79&Y=375&INFO_FORMAT=text%2Fhtml&QUERY_LAYERS=Workspace%3ALayer&FEATURE_COUNT=50&Srs=EPSG%3A4326&Layers=Workspace%3ALayer&Styles=&WIDTH=177&HEIGHT=512&format=image%2Fpng 
>>>> <http://myownhomepage.xyz/geoserver/wms?REQUEST=GetFeatureInfo&EXCEPTIONS=application%2Fvnd.ogc.se_xml&BBOX=12.327023%2C47.673%2C12.362977%2C47.777&X=79&Y=375&INFO_FORMAT=text%2Fhtml&QUERY_LAYERS=Workspace%3ALayer&FEATURE_COUNT=50&Srs=EPSG%3A4326&Layers=Workspace%3ALayer&Styles=&WIDTH=177&HEIGHT=512&format=image%2Fpng> 
>>>> <http://myownhomepage.xyz/geoserver/wms?REQUEST=GetFeatureInfo&EXCEPTIONS=application%2Fvnd.ogc.se_xml&BBOX=12.327023%2C47.673%2C12.362977%2C47.777&X=79&Y=375&INFO_FORMAT=text%2Fhtml&QUERY_LAYERS=Workspace%3ALayer&FEATURE_COUNT=50&Srs=EPSG%3A4326&Layers=Workspace%3ALayer&Styles=&WIDTH=177&HEIGHT=512&format=image%2Fpng 
>>>> <http://myownhomepage.xyz/geoserver/wms?REQUEST=GetFeatureInfo&EXCEPTIONS=application%2Fvnd.ogc.se_xml&BBOX=12.327023%2C47.673%2C12.362977%2C47.777&X=79&Y=375&INFO_FORMAT=text%2Fhtml&QUERY_LAYERS=Workspace%3ALayer&FEATURE_COUNT=50&Srs=EPSG%3A4326&Layers=Workspace%3ALayer&Styles=&WIDTH=177&HEIGHT=512&format=image%2Fpng>>
>>>
>>> GeoServer runs as a .war within Tomcat and OpenLayers is on the same 
>>> server. I really can't believe why the same code with the same 
>>> request on the same server is once getting a response and the other 
>>> time it is not. Is there a possibility that it is a proxy-issue or 
>>> maybe a problem with the encoding?
>>>
>>> Thanks, Pascal




More information about the Users mailing list