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
                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) {

    filterQueryString: function (queryString) {
        if (queryString.length > 705) {
            throw "The feature info request cannot be handled. Remove one or more layers and try again";
  • why not ask for the response in a format other than JSON so it doesn't contain the WKT by default? – Ian Turton Feb 15 '16 at 13:05
  • which format would you recommend? – user3523583 Feb 15 '16 at 14:25

The obvious solution to this problem is to remove the geometry element after you get the response back, after all that is why you asked for JSON so you could manipulate it using a JavaScript function. That is why you asked for it right? not just because it's trendy?

The easier way to do this is to use one of the other formats that your server supports, for any recent GeoServer this is:

    <Format>text/xml; subtype=gml/3.1.1</Format>

Obviously the GML options are out if you don't want the geometries, which leaves us with text/plain, text/xml and text/html.

Text/plain gives me:

Results for FeatureType 'http://www.openplans.org/topp:states':
the_geom = [GEOMETRY (Polygon) with 56 points]
STATE_NAME = Colorado
LAND_KM = 268659.501
WATER_KM = 960.364
PERSONS = 3294394.0
FAMILIES = 854214.0
HOUSHOLD = 1282489.0
MALE = 1631295.0
FEMALE = 1663099.0
WORKERS = 1233023.0
DRVALONE = 1216639.0
CARPOOL = 210274.0
PUBTRANS = 46983.0
EMPLOYED = 1633281.0
UNEMPLOY = 99438.0
SERVICE = 421079.0
MANUAL = 181760.0
P_MALE = 0.495
P_FEMALE = 0.505
SAMP_POP = 512677.0

Text/XML gives me GML so we can abandon that, and text/html gives:

<table class="featureInfo">
  <caption class="featureInfo">states</caption>
    <th >STATE_NAME</th>
    <th >STATE_FIPS</th>
    <th >SUB_REGION</th>
    <th >STATE_ABBR</th>
    <th >LAND_KM</th>
    <th >WATER_KM</th>
    <th >PERSONS</th>
    <th >FAMILIES</th>
    <th >HOUSHOLD</th>
    <th >MALE</th>
    <th >FEMALE</th>
    <th >WORKERS</th>
    <th >DRVALONE</th>
    <th >CARPOOL</th>
    <th >PUBTRANS</th>
    <th >EMPLOYED</th>
    <th >UNEMPLOY</th>
    <th >SERVICE</th>
    <th >MANUAL</th>
    <th >P_MALE</th>
    <th >P_FEMALE</th>
    <th >SAMP_POP</th>



That's quite verbose but if all you plan to do is produce a tabular output then it might work for you.

  • Yes, I eventually opted for the text/plain option and get info from there. Thanks – user3523583 Feb 16 '16 at 23:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.