Discussion:
[OpenLayers-Users] GetFeatureInfo map.events.register for *many* WMS layers
cgp
2009-09-14 19:02:04 UTC
Permalink
I have about 10 or more WMS layers that I'm adding to the map. I'm using
GetFeatureInfo to get values for each layer. So I have 10 of these:
------------------------------------------------------------------------------
map.events.register('click', map, function (e) {
if (map.layers[layer_index].visibility==true) {
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[layer_index].params.LAYERS,
FEATURE_COUNT: 50,
Styles: '',
Layers: layer_name,
srs: 'EPSG:900913',
WIDTH: map.size.w,
HEIGHT: map.size.h,
format: 'image/png' };
event = e;
OpenLayers.loadURL("http://app-serv-01-uat/geoserver/wms", params, this,
setHTML, setHTML);
}
OpenLayers.Event.stop(e);
});
------------------------------------------------------------------------------

And since I have 10 of those for each of the 10 different layers, my code is
getting too long, messy and unmanageable. I tried to refactor it by creating
a for loop:

------------------------------------------------------------------------------
var layers_names = new
Array('sde:forests','sde:lakes','sde:trails,'sde:boundary','sde:buffallo','sde:fish','sde:birds','sde:picnic_sites','sde:rivers','sde:camping');
var layer_indices = new Array(5,6,7,8,9,10,11,12,13,14);

var layer_name;
var layer_index;

for (var i=0; i<layers_names.length; i++) {
layer_name = layers_names[i];
layer_index = layer_indices[i];

alert(layer_name+" "+layer_index);

map.events.register('click', map, function (e) {
if (map.layers[layer_index].visibility==true) {
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[layer_index].params.LAYERS,
FEATURE_COUNT: 50,
Styles: '',
Layers: layer_name,
srs: 'EPSG:900913',
WIDTH: map.size.w,
HEIGHT: map.size.h,
format: 'image/png' };
event = e;
OpenLayers.loadURL("http://app-serv-01-uat/geoserver/wms", params, this,
setHTML, setHTML);
}
OpenLayers.Event.stop(e);
});
}
------------------------------------------------------------------------------

My problem with this is that the click event sticks to the last array value
only. In this example, the GetFeatureInfo will only be fired on layer 12,
'sde:camping'. For the rest of the previous layers, it won't fire at all. I
might be missing something, so can someone help me out? Thank you very much.
--
View this message in context: http://n2.nabble.com/GetFeatureInfo-map-events-register-for-many-WMS-layers-tp3644430p3644430.html
Sent from the OpenLayers Users mailing list archive at Nabble.com.
Andreas Hocevar
2009-09-14 19:12:07 UTC
Permalink
Hi,

Just remove the line

OpenLayers.Event.stop(e);


for all but the 1st layer.

Regards,
Andreas.
Post by cgp
I have about 10 or more WMS layers that I'm adding to the map. I'm using
------------------------------------------------------------------------------
map.events.register('click', map, function (e) {
if (map.layers[layer_index].visibility==true) {
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[layer_index].params.LAYERS,
FEATURE_COUNT: 50,
Styles: '',
Layers: layer_name,
srs: 'EPSG:900913',
WIDTH: map.size.w,
HEIGHT: map.size.h,
format: 'image/png' };
event = e;
OpenLayers.loadURL("http://app-serv-01-uat/geoserver/wms", params, this,
setHTML, setHTML);
}
OpenLayers.Event.stop(e);
});
------------------------------------------------------------------------------
And since I have 10 of those for each of the 10 different layers, my code is
getting too long, messy and unmanageable. I tried to refactor it by creating
------------------------------------------------------------------------------
var layers_names = new
Array('sde:forests','sde:lakes','sde:trails,'sde:boundary','sde:buffallo','sde:fish','sde:birds','sde:picnic_sites','sde:rivers','sde:camping');
var layer_indices = new Array(5,6,7,8,9,10,11,12,13,14);
var layer_name;
var layer_index;
for (var i=0; i<layers_names.length; i++) {
layer_name = layers_names[i];
layer_index = layer_indices[i];
alert(layer_name+" "+layer_index);
map.events.register('click', map, function (e) {
if (map.layers[layer_index].visibility==true) {
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[layer_index].params.LAYERS,
FEATURE_COUNT: 50,
Styles: '',
Layers: layer_name,
srs: 'EPSG:900913',
WIDTH: map.size.w,
HEIGHT: map.size.h,
format: 'image/png' };
event = e;
OpenLayers.loadURL("http://app-serv-01-uat/geoserver/wms", params, this,
setHTML, setHTML);
}
OpenLayers.Event.stop(e);
});
}
------------------------------------------------------------------------------
My problem with this is that the click event sticks to the last array value
only. In this example, the GetFeatureInfo will only be fired on layer 12,
'sde:camping'. For the rest of the previous layers, it won't fire at all. I
might be missing something, so can someone help me out? Thank you very much.
--
Andreas Hocevar
OpenGeo - http://opengeo.org/
Expert service straight from the developers.
Ian Turton
2009-09-14 19:22:37 UTC
Permalink
You should probably use the same variable for the layers and
query_layers parameters - there is some debate over whether they must
match or not (GeoServer atleast requires all the query layers to be
listed in the layers param).

I'm also not quite clear as to why you can't roll all the layers in to
one request?

Ian
cgp
2009-09-14 19:47:17 UTC
Permalink
How do you "roll all the layers in to one request"? All the examples that
I've seen only have one layer at a time.
Post by Ian Turton
You should probably use the same variable for the layers and
query_layers parameters - there is some debate over whether they must
match or not (GeoServer atleast requires all the query layers to be
listed in the layers param).
I'm also not quite clear as to why you can't roll all the layers in to
one request?
Ian
_______________________________________________
Users mailing list
http://openlayers.org/mailman/listinfo/users
--
View this message in context: http://n2.nabble.com/GetFeatureInfo-map-events-register-for-many-WMS-layers-tp3644430p3644673.html
Sent from the OpenLayers Users mailing list archive at Nabble.com.
Ian Turton
2009-09-14 22:09:59 UTC
Permalink
Post by cgp
How do you "roll all the layers in to one request"? All the examples that
I've seen only have one layer at a time.
You can put as many layers in to each of the layers parameters as you
want separated by commas.

Ian
--
Ian Turton

Sent from State College, Pennsylvania, United States
cgp
2009-09-14 22:29:47 UTC
Permalink
Ah ok. That works well for making the code compact, but the click event grabs
feature info for all the layers at the same time. I want it to only get the
feature info if the layer is currently selected. That's why I have the
condition "if (map.layers[curr_layer_index].visibility==true)" for each of
the layers.
Post by Ian Turton
Post by cgp
How do you "roll all the layers in to one request"? All the examples that
I've seen only have one layer at a time.
You can put as many layers in to each of the layers parameters as you
want separated by commas.
Ian
--
Ian Turton
Sent from State College, Pennsylvania, United States
_______________________________________________
Users mailing list
http://openlayers.org/mailman/listinfo/users
--
View this message in context: http://n2.nabble.com/GetFeatureInfo-map-events-register-for-many-WMS-layers-tp3644430p3645435.html
Sent from the OpenLayers Users mailing list archive at Nabble.com.
S***@inspq.qc.ca
2009-09-18 13:27:15 UTC
Permalink
Hi,
I'm using WMSGetFeatureInfo to query a specific layer. The information is
retrieved from the same server/domain where the application and mapserver
are installed.
The answer I get is "The requested URL /cgi-bin/proxy.cgi was not found on
this server."
I read this http://faq.openlayers.org/proxyhost/all/
and I already set a proxy on another server for another project.

But in this case my understanding was that I don't need a proxy since I'm
not querying a remote server. I can't see why my code is requesting
/cgi-bin/proxy. It should call directly cgi-bin/mapserver? isn'it?

Here is my code
infoControls =
{
click: new OpenLayers.Control.WMSGetFeatureInfo({
//url: 'http://IP
address/cgi-bin/mapserv.exe?map=/ms4w/paccSante/map/paccsante_hlm.map&',
maxFeatures: 12,
title: 'Identify features by clicking',
layers: [overlays['HLM']],
queryVisible: true,
infoFormat:'text/html'
})
}
infoControls['click'].events.register("getfeatureinfo", this, showInfo);
map.addControl(infoControls['click']);
infoControls['click'].activate();

If I uncomment the url parameter I got the same result.
What could be the reason why it is looking for a proxy?
This line IS NOT in my code
OpenLayers.ProxyHost = "/cgi-bin/proxy.cgi?url=";


thanks
Steve
Christopher Schmidt
2009-09-18 14:05:04 UTC
Permalink
Post by S***@inspq.qc.ca
Hi,
I'm using WMSGetFeatureInfo to query a specific layer. The information is
retrieved from the same server/domain where the application and mapserver
are installed.
The answer I get is "The requested URL /cgi-bin/proxy.cgi was not found on
this server."
I read this http://faq.openlayers.org/proxyhost/all/
and I already set a proxy on another server for another project.
But in this case my understanding was that I don't need a proxy since I'm
not querying a remote server. I can't see why my code is requesting
/cgi-bin/proxy. It should call directly cgi-bin/mapserver? isn'it?
Here is my code
infoControls =
{
click: new OpenLayers.Control.WMSGetFeatureInfo({
//url: 'http://IP
address/cgi-bin/mapserv.exe?map=/ms4w/paccSante/map/paccsante_hlm.map&',
maxFeatures: 12,
title: 'Identify features by clicking',
layers: [overlays['HLM']],
queryVisible: true,
infoFormat:'text/html'
})
}
infoControls['click'].events.register("getfeatureinfo", this, showInfo);
map.addControl(infoControls['click']);
infoControls['click'].activate();
If I uncomment the url parameter I got the same result.
What could be the reason why it is looking for a proxy?
This line IS NOT in my code
OpenLayers.ProxyHost = "/cgi-bin/proxy.cgi?url=";
If you type "OpenLayers.ProxyHost" into Firebug or some other debugging tool,
what does it tell you?

-- Chris
Post by S***@inspq.qc.ca
thanks
Steve
_______________________________________________
Users mailing list
http://openlayers.org/mailman/listinfo/users
--
Christopher Schmidt
MetaCarta
S***@inspq.qc.ca
2009-09-18 14:42:54 UTC
Permalink
That works!
Not sure to understand why though?

thanks
Steve


Steve Toutant, M. Sc.
Analyste en géomatique
Secteur environnement
Direction des risques biologiques, environnementaux et occupationnels
Institut national de santé publique du Québec
945, avenue Wolfe
Québec, Qc G1V 5B3
Tél.: (418) 650-5115 #5281
Fax.: (418) 654-3144
***@inspq.qc.ca
http://www.inspq.qc.ca





François Van Der Biest <***@camptocamp.com>
18/09/2009 10:34 AM

A
***@inspq.qc.ca
cc

Objet
Re: [OpenLayers-Users] WMSGetFeatureInfo and proxy








Hi Steve,

What if you try with this url :
url: '/cgi-bin/mapserv.exe?map=/ms4w/paccSante/map/paccsante_hlm.map&',

F.
Post by S***@inspq.qc.ca
Hi,
I'm using WMSGetFeatureInfo to query a specific layer. The information
is
Post by S***@inspq.qc.ca
retrieved from the same server/domain where the application and
mapserver
Post by S***@inspq.qc.ca
are installed.
The answer I get is "The requested URL /cgi-bin/proxy.cgi was not found
on
Post by S***@inspq.qc.ca
this server."
I read this http://faq.openlayers.org/proxyhost/all/
and I already set a proxy on another server for another project.
But in this case my understanding was that I don't need a proxy since
I'm
Post by S***@inspq.qc.ca
not querying a remote server. I can't see why my code is requesting
/cgi-bin/proxy. It should call directly cgi-bin/mapserver? isn'it?
Here is my code
infoControls =
{
click: new OpenLayers.Control.WMSGetFeatureInfo({
//url: 'http://IP
address/cgi-bin/mapserv.exe?map=/ms4w/paccSante/map/paccsante_hlm.map&',
maxFeatures: 12,
title: 'Identify features by clicking',
layers: [overlays['HLM']],
queryVisible: true,
infoFormat:'text/html'
})
}
infoControls['click'].events.register("getfeatureinfo", this, showInfo);
map.addControl(infoControls['click']);
infoControls['click'].activate();
If I uncomment the url parameter I got the same result.
What could be the reason why it is looking for a proxy?
This line IS NOT in my code
OpenLayers.ProxyHost = "/cgi-bin/proxy.cgi?url=";
thanks
Steve
_______________________________________________
Users mailing list
http://openlayers.org/mailman/listinfo/users
S***@inspq.qc.ca
2009-09-18 14:53:46 UTC
Permalink
firebug found OpenLayers.ProxyHost into example.js
That is a script from mapfish used for the print widget example.

Just removed it and now it is working with or without specifying the url
in the parameters list of WMSGetFeatureInfo.

Thanks for your help,
Steve

Steve Toutant, M. Sc.
Analyste en géomatique
Secteur environnement
Direction des risques biologiques, environnementaux et occupationnels
Institut national de santé publique du Québec
945, avenue Wolfe
Québec, Qc G1V 5B3
Tél.: (418) 650-5115 #5281
Fax.: (418) 654-3144
***@inspq.qc.ca
http://www.inspq.qc.ca





Christopher Schmidt <***@metacarta.com>@openlayers.org
Envoyé par : users-***@openlayers.org
18/09/2009 10:05 AM

A
***@inspq.qc.ca
cc
***@openlayers.org
Objet
Re: [OpenLayers-Users] WMSGetFeatureInfo and proxy
Post by S***@inspq.qc.ca
Hi,
I'm using WMSGetFeatureInfo to query a specific layer. The information
is
Post by S***@inspq.qc.ca
retrieved from the same server/domain where the application and
mapserver
Post by S***@inspq.qc.ca
are installed.
The answer I get is "The requested URL /cgi-bin/proxy.cgi was not found
on
Post by S***@inspq.qc.ca
this server."
I read this http://faq.openlayers.org/proxyhost/all/
and I already set a proxy on another server for another project.
But in this case my understanding was that I don't need a proxy since
I'm
Post by S***@inspq.qc.ca
not querying a remote server. I can't see why my code is requesting
/cgi-bin/proxy. It should call directly cgi-bin/mapserver? isn'it?
Here is my code
infoControls =
{
click: new OpenLayers.Control.WMSGetFeatureInfo({
//url: 'http://IP
address/cgi-bin/mapserv.exe?map=/ms4w/paccSante/map/paccsante_hlm.map&',
maxFeatures: 12,
title: 'Identify features by clicking',
layers: [overlays['HLM']],
queryVisible: true,
infoFormat:'text/html'
})
}
infoControls['click'].events.register("getfeatureinfo", this, showInfo);
map.addControl(infoControls['click']);
infoControls['click'].activate();
If I uncomment the url parameter I got the same result.
What could be the reason why it is looking for a proxy?
This line IS NOT in my code
OpenLayers.ProxyHost = "/cgi-bin/proxy.cgi?url=";
If you type "OpenLayers.ProxyHost" into Firebug or some other debugging
tool,
what does it tell you?

-- Chris
Post by S***@inspq.qc.ca
thanks
Steve
_______________________________________________
Users mailing list
http://openlayers.org/mailman/listinfo/users
--
Christopher Schmidt
MetaCarta
vrbikdan
2011-04-29 12:18:00 UTC
Permalink
Hi,
I haven't time and I have similar problem :(. I have six layers and I need
GetFeatureInfo to get their values. Now, when is some overlaps of two points
from different layers values only from one layer is shown. But I need both
values in one click and another values, when I click on the other point in
my map. I tried advices written in this topic, but anything works. Here is
part of my code:

map.events.register('click', map, function (e) {
document.getElementById('infoDiv').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: 'body2',
FEATURE_COUNT: 50,
Layers:
['dp:body2','dp:body3','dp:body4WGS84','dp:body5','dp:body6','dp:body7'],
Styles: '',
Srs: 'EPSG:900913',
WIDTH: map.size.w,
HEIGHT: map.size.h,
format: 'image/png' };

OpenLayers.loadURL("http://localhost:8080/geoserver/wms", params, this,
setHTML, setHTML);
event=e;
//OpenLayers.Event.stop(e);
});

this part of code is six times in my code, only difference is in
QUERY_LAYERS (it is messy, I know). Can you anyone help me?

Thanks for help,
Dan--
View this message in context: http://osgeo-org.1803224.n2.nabble.com/GetFeatureInfo-map-events-register-for-many-WMS-layers-tp3644430p6316662.html
Sent from the OpenLayers Users mailing list archive at Nabble.com.
vrbikdan
2011-04-29 14:36:56 UTC
Permalink
Hi,
I haven't time and I have similar problem :(. I have six layers and I need
WMSGetFeatureInfo to get their values. Now, when is some overlaps of two
points from different layers, values only from one layer is shown. But I
need both values in one click and another values, when I click on the other
point in my map. I tried advices written in this topic, but anything works.
Second problem is, that sometimes, response of WMSGetFeatureInfo is shown
only for little while and than dissapear even I don't click anywhere else.
Here is part of my code:

infoControls2 = {
click: new OpenLayers.Control.WMSGetFeatureInfo({
url: 'http://localhost:8080/geoserver/wms',
title: 'Identify features by clicking',
layers: [body2],
queryVisible: true})
};

for (var i in infoControls2) {
infoControls2[i].events.register("getfeatureinfo", this,
showInfo);
map.addControl(infoControls2[i]);
};

function showInfo(evt) {

$('infoDiv').innerHTML = evt.text;
};
infoControls2.click.activate();

this part of code is six times in my code, only difference is in Layers, and
name of variable (it is messy, I know). Can you anyone help me?

Thanks for help,
Dan--
View this message in context: http://osgeo-org.1803224.n2.nabble.com/GetFeatureInfo-map-events-register-for-many-WMS-layers-tp3644430p6317115.html
Sent from the OpenLayers Users mailing list archive at Nabble.com.
Loading...