From 376c33338c1cbcbd42b6f17ec1ee6e5e2d0672ff Mon Sep 17 00:00:00 2001 From: Bernhard Kiselka Date: Tue, 22 Nov 2016 12:40:11 +0100 Subject: [PATCH] add option usePOST for optionally using POST insetad of GET for WMSGetFeatureInfo requests (idea from Protocol/HTTP.js) fixes https://trac.osgeo.org/openlayers/ticket/3357 --- lib/OpenLayers/Control/WMSGetFeatureInfo.js | 52 ++++++++++++++++++--- 1 file changed, 45 insertions(+), 7 deletions(-) diff --git a/lib/OpenLayers/Control/WMSGetFeatureInfo.js b/lib/OpenLayers/Control/WMSGetFeatureInfo.js index 94b60052b3..eb14f6c158 100644 --- a/lib/OpenLayers/Control/WMSGetFeatureInfo.js +++ b/lib/OpenLayers/Control/WMSGetFeatureInfo.js @@ -156,6 +156,13 @@ OpenLayers.Control.WMSGetFeatureInfo = OpenLayers.Class(OpenLayers.Control, { */ hoverRequest: null, + /** + * APIProperty: usePOST + * {Boolean} true if the GetFeatureInfo request are done with POST requests + * instead of GET, defaults to false. + */ + usePOST: false, + /** * APIProperty: events * {} Events instance for listeners and triggering @@ -435,7 +442,7 @@ OpenLayers.Control.WMSGetFeatureInfo = OpenLayers.Class(OpenLayers.Control, { if(this.drillDown === false) { var wmsOptions = this.buildWMSOptions(this.url, layers, clickPosition, layers[0].params.FORMAT); - var request = OpenLayers.Request.GET(wmsOptions); + var request = this.doRequest(clickPosition, options, wmsOptions); if (options.hover === true) { this.hoverRequest = request; @@ -448,7 +455,6 @@ OpenLayers.Control.WMSGetFeatureInfo = OpenLayers.Class(OpenLayers.Control, { var services = {}, url; for(var i=0, len=layers.length; i} The position on the map where the + * mouse event occurred. + * options - {Object} additional options for this method. + * wmsOptions - {Array({Object})} with the relevant WMS options for the + * GetFeatureInfo request gotten by buildWMSOptions. + */ + doRequest: function (clickPosition, options, wmsOptions) { + var usePOST = (options.usePOST !== undefined) ? + options.usePOST : this.usePOST; + var request; + if (usePOST) { + var headers = wmsOptions.headers || {}; + headers["Content-Type"] = "application/x-www-form-urlencoded"; + request = OpenLayers.Request.POST({ + url: wmsOptions.url, + callback: function (request) { + this.handleResponse(clickPosition, request, wmsOptions.url); + }, + data: OpenLayers.Util.getParameterString(wmsOptions.params), + headers: headers, + scope: this + }); + } else { + request = OpenLayers.Request.GET(wmsOptions); + } + return request; + }, + /** * Method: triggerGetFeatureInfo * Trigger the getfeatureinfo event when all is done