I am working in OpenLayers 2, setting up a WMSFeatureinfo Object that has both 'beforegetfeatureinfo' and 'getfeatureinfo' event listeners. In the response I want to strip out all the WKT for the geometry and in order to do so I have to include in the "propertyName" vendorParams all the properties I want to filter (all apart from the geometry). This methods sometimes results in very long query strings that the server cannot handle getting a 502 response type.
Considered that I cannot change the server settings, I would like to count the query string length and in case this is longer that a certain number of characters exit the map init function and blocking the code execution, preventing the identify control to send the request.
I tried to put a try catch statement on the 'beforegetfeatureinfo' event listener but the request is sent anyway. Is there a method to exit the code and ignore the event listener before the request is sent?
identifyControl = new OpenLayers.Control.WMSGetFeatureInfo({
url: dataurl,
properties: getVisibleAttributes(),
layers: getIdentifiableLayers(),
queryVisible: false,
format: new OpenLayers.Format.JSON,
infoFormat: 'application/json',
eventListeners: {
'beforegetfeatureinfo': function (e) {
identifyControl.layers = getIdentifiableLayers();
identifyControl.url = dataurl + data.dataurlExt;
this.vendorParams = {
STYLES: "",
PROPERTYNAME: this.formatPropertyNamesParameter()
}
try {
//here I check for the query string lenght
this.filterQueryString(this.vendorParams.PROPERTYNAME)
}
catch (err) {
// I would like to exit the code here but it does not happen
}
}
},
'getfeatureinfo': function (e) {
featuresCounter = 0;
identifyLocation = map.getLonLatFromPixel(e.xy);
//Filter here
var finalResults = new Array();
for (var i = 0; i < e.features.features.length; i++) {
var id = e.features.features[i].id;
var layer = id.substr(0, id.indexOf('.'));
//TODO: only request the attributes that are needed with GeoServer vendor parameter propertyName
var visibleAttributes = getVisibleLayerAttributes(layer);
var results = filterAttributes(visibleAttributes, e.features.features[i]);
if (results.length > 0) {
finalResults.push(results);
}
}
createPopupHTML(finalResults);
},
filterQueryString: function (queryString) {
if (queryString.length > 705) {
throw "The feature info request cannot be handled. Remove one or more layers and try again";
}
}
});