I am trying to use OpenLayers.Control.WMSGetFeatureInfo in combination with OpenLayers.Popup.FramedCloud to retrieve info from my geoserver and show them in a popup window. This is my code:
var map,wms,point;
function load() {
map = new OpenLayers.Map('map',{});
wms = new OpenLayers.Layer.WMS( "OpenLayers WMS","http://vmap0.tiles.osgeo.org/wms/vmap0", {layers: 'basic'} );
// overlay layer from geoserver
point = new OpenLayers.Layer.WMS( "OpenLayers WMS","http://localhost:8080/geoserver/wms", {layers: 'cite:obj_geom',transparent: true},{projection: new OpenLayers.Projection("EPSG:900913")} );
// add layers
map.addLayers([point,wms]);
map.zoomToExtent(
new OpenLayers.Bounds(36.190737, 35.353912,35.150577, 50.274810)
);
var infoControls = {
click: new OpenLayers.Control.WMSGetFeatureInfo({
url: "http://localhost:8080/geoserver/wms",
title: 'Identify features by clicking',
layers: [point],
maxFeatures: 2,
infoFormat: 'text/plain',
queryVisible: true,
**eventListeners: {/*
getfeatureinfo: function(event) {
map.addPopup(new OpenLayers.Popup.FramedCloud(
"chicken",
map.getLonLatFromPixel(event.xy),
null,
event.text,
null,
true
));
}***/
}
})
};
for (var i in infoControls) {
infoControls[i].events.register("getfeatureinfo", this, showInfo);
map.addControl(infoControls[i]);
}
infoControls.click.activate();
} // end function
function showInfo(evt) {
alert('hello');
console.log("Hurray!");
}
</script>
I have placed my *.php file inside the geoserver directory therefore I don't need a proxy to run it. Using firebug I can see that when I click a point a request is made and I get back as a response the feature id. Everything works fine. But I can not figure out how to show the popup window. In internet I found code that uses an eventlistener but my problem is that as soon as I add the evenlistener then I don't get the map. I see nothing on my screen. What causes the problem for this? Any hint or help is highly appreciated.
Thanks D.
A combination of syntax errors and using the wrong function for what I wanted to do lead to this error. Using Firebug helped me to find all the syntax errors and kill them.