I have an OpenLayers/GeoExtJS map that I have a WMSGetFeatureInfo popup come up every time a user clicks a point on the map. However, the popup is displaying results even for layers which are not visible at the resolution which is set at the time of the user’s click. The OpenLayers layer.calculateInRange() tells me quite nicely which layers are currently in range or not, but I do not know how to eliminate them from the getfeatureinfo request…
Even trying the eventListener beforegetfeatureinfo did not work…
Any ideas would truly be wonderful 🙂
var layersToBeQueried = [layerA, layerB, layerC, layerD, layerE];
function removeLayersOutOfRange(layerArray) {
for (var i = 0; i < layerArray.length; i++) {
alert(layerArray[i].name);
if (layerArray[i].calculateInRange() == false) {
layerArray.splice(i, 1);
}
}
return layerArray;
}
var info = new OpenLayers.Control.WMSGetFeatureInfo({
url: layerURL,
layerUrls: [layerURL],
title: 'Identify features by clicking',
queryVisible: true,
eventListeners: {
beforegetfeatureinfo: function (event) {
this.layers = removeLayersOutOfRange(layersToBeQueried);
},
getfeatureinfo: function (event) {
if (event.text.length <= 687) { } else {
popup = new GeoExt.Popup({
title: "Popup",
location: event.xy,
autoScroll: true,
height: $('#myViewPort').height() - 250,
maximizable: true,
collapsible: true,
map: mapPanel.map,
anchored: true,
html: '<div id="popupWrap"></div>',
listeners: {
close: function () {
// closing a popup destroys it, but our reference is truthy
popup = null;
}
}
});
popup.show();
}//end if
}//end getfeatureinfo
}//end eventListeners
});//end OpenLayers.Control.WMSGetFeatureInfo
mapPanel.map.addControl(info);
info.activate();
Thanks,
elshae
Not a solution to your original problem, but I think you should rethink the removeLayersOutOfRange function. Using splice on you array will change it while in the loop, thus changing the indices as well. This means you won’t loop through all layers correctly.
I would suggest you create a new array and push the layers that are in range into that array, passing that on instead of editing the input array.
Something like this (untested):
Looking at your original problem now. Maybe the layer logic could be performed when the search is completed? In the getFeatureInfo method, asking the layer logic which layers are visible, and then compile a message only using info from those layers? Messing with the query layers could perhaps be the culprit here. Not having experience in that, only guessing…