diff --git a/lib/OpenLayers/Control/WMSGetFeatureInfo.js b/lib/OpenLayers/Control/WMSGetFeatureInfo.js index 6fdc14b33c..fa987c0d0d 100644 --- a/lib/OpenLayers/Control/WMSGetFeatureInfo.js +++ b/lib/OpenLayers/Control/WMSGetFeatureInfo.js @@ -334,25 +334,36 @@ OpenLayers.Control.WMSGetFeatureInfo = OpenLayers.Class(OpenLayers.Control, { layerNames = layerNames.concat(layers[i].params.LAYERS); styleNames = styleNames.concat(this.getStyleNames(layers[i])); } + var params = OpenLayers.Util.extend({ + service: "WMS", + version: layers[0].params.VERSION, + request: "GetFeatureInfo", + layers: layerNames, + query_layers: layerNames, + styles: styleNames, + bbox: this.map.getExtent().toBBOX(null, + layers[0].reverseAxisOrder()), + feature_count: this.maxFeatures, + height: this.map.getSize().h, + width: this.map.getSize().w, + format: format, + info_format: this.infoFormat + }, (parseFloat(layers[0].params.VERSION) >= 1.3) ? + { + crs: this.map.getProjection(), + i: clickPosition.x, + j: clickPosition.y + } : + { + srs: this.map.getProjection(), + x: clickPosition.x, + y: clickPosition.y + } + ); + OpenLayers.Util.applyDefaults(params, this.vendorParams); return { url: url, - params: OpenLayers.Util.applyDefaults({ - service: "WMS", - version: "1.1.0", - request: "GetFeatureInfo", - layers: layerNames, - query_layers: layerNames, - styles: styleNames, - bbox: this.map.getExtent().toBBOX(), - srs: this.map.getProjection(), - feature_count: this.maxFeatures, - x: clickPosition.x, - y: clickPosition.y, - height: this.map.getSize().h, - width: this.map.getSize().w, - format: format, - info_format: this.infoFormat - }, this.vendorParams), + params: OpenLayers.Util.upperCaseObject(params), callback: function(request) { this.handleResponse(clickPosition, request); }, diff --git a/lib/OpenLayers/Layer/WMS.js b/lib/OpenLayers/Layer/WMS.js index 1fb4f87398..9daaa966c5 100644 --- a/lib/OpenLayers/Layer/WMS.js +++ b/lib/OpenLayers/Layer/WMS.js @@ -156,6 +156,20 @@ OpenLayers.Layer.WMS = OpenLayers.Class(OpenLayers.Layer.Grid, { return obj; }, + /** + * APIMethod: reverseAxisOrder + * Returns true if the axis order is reversed for the WMS version and + * projection of the layer. + * + * Returns: + * {Boolean} true if the axis order is reversed, false otherwise. + */ + reverseAxisOrder: function() { + return (parseFloat(this.params.VERSION) >= 1.3 && + OpenLayers.Util.indexOf(this.yx, + this.map.getProjectionObject().getCode()) !== -1) + }, + /** * Method: getURL * Return a GetMap query string for this layer @@ -175,16 +189,10 @@ OpenLayers.Layer.WMS = OpenLayers.Class(OpenLayers.Layer.Grid, { var imageSize = this.getImageSize(); var newParams = {}; // WMS 1.3 introduced axis order - if (parseFloat(this.params.VERSION) >= 1.3 && - OpenLayers.Util.indexOf(this.yx, - this.map.getProjectionObject().getCode()) !== -1) { - - newParams.BBOX = this.encodeBBOX ? bounds.toBBOX(null, true) : - bounds.toArray(true); - } else { - newParams.BBOX = this.encodeBBOX ? bounds.toBBOX() : - bounds.toArray(); - } + var reverseAxisOrder = this.reverseAxisOrder(); + newParams.BBOX = this.encodeBBOX ? + bounds.toBBOX(null, reverseAxisOrder) : + bounds.toArray(reverseAxisOrder); newParams.WIDTH = imageSize.w; newParams.HEIGHT = imageSize.h; var requestString = this.getFullRequestString(newParams); diff --git a/tests/Control/WMSGetFeatureInfo.html b/tests/Control/WMSGetFeatureInfo.html index ad353ab07f..7d78be898b 100644 --- a/tests/Control/WMSGetFeatureInfo.html +++ b/tests/Control/WMSGetFeatureInfo.html @@ -216,13 +216,13 @@ "url from first layer used" ); t.eq( - log.options && log.options.params.styles.join(","), + log.options && log.options.params.STYLES.join(","), "a,b,c,d,a,b,c,d,,,,,,,,", "Styles merged correctly" ); t.eq( - log.options && log.options.params.format, + log.options && log.options.params.FORMAT, "image/jpeg", "Required 'format' parameter included" ); @@ -293,13 +293,13 @@ control.layerUrls = ["http://a.mirror/wms", "http://b.mirror/wms"]; control.getInfoForClick({xy: {x: 50, y: 50}}); t.eq(log.options && log.options.url, "http://host/wms", "some match, request issued"); - t.eq(log.options && log.options.params["query_layers"].join(","), "a,b", "selected layers queried"); + t.eq(log.options && log.options.params["QUERY_LAYERS"].join(","), "a,b", "selected layers queried"); // show that a layer can be matched if it has a urls array itself (first needs to be matched) log = {}; control.layerUrls = ["http://c.mirror/wms"]; control.getInfoForClick({xy: {x: 50, y: 50}}); - t.eq(log.options && log.options.params["query_layers"].join(","), "c", "layer with urls array can be queried"); + t.eq(log.options && log.options.params["QUERY_LAYERS"].join(","), "c", "layer with urls array can be queried"); // clean up OpenLayers.Request.GET = _request; @@ -339,7 +339,7 @@ OpenLayers.Request.GET = function(options) { count++; if (count == 1) { - t.eq(options.params["query_layers"].join(","), "a,c", "Layers should be grouped by service url"); + t.eq(options.params["QUERY_LAYERS"].join(","), "a,c", "Layers should be grouped by service url"); t.eq(options.url, "http://localhost/wms", "Correct url used for first request"); } else if (count == 2) { t.eq(options.url, "http://myhost/wms", "Correct url used for second request"); @@ -352,6 +352,57 @@ map.destroy(); } + function test_GetFeatureInfo_WMS13(t) { + t.plan(4); + var map = new OpenLayers.Map("map", { + getExtent: function() {return(new OpenLayers.Bounds(-180,-90,180,90));} + } + ); + + var a = new OpenLayers.Layer.WMS(null, "http://localhost/wms", { + layers: "a", + version: "1.3.0" + }); + map.addLayer(a); + + var click = new OpenLayers.Control.WMSGetFeatureInfo({ + }); + + map.addControl(click); + var log = {}; + var _request = OpenLayers.Request.GET; + OpenLayers.Request.GET = function(options) { + log.options = options; + }; + click.activate(); + click.getInfoForClick({xy: {x: 50, y: 60}}); + OpenLayers.Request.GET = _request; + t.eq( + log.options && log.options.params.CRS, + "EPSG:4326", + "Since it is WMS 1.3 use CRS parameter instead of SRS in the GetFeatureInfo request" + ); + + t.eq( + log.options && log.options.params.I, + 50, + "Since it is WMS 1.3 use I parameter instead of X in the GetFeatureInfo request" + ); + + t.eq( + log.options && log.options.params.J, + 60, + "Since it is WMS 1.3 use J parameter instead of Y in the GetFeatureInfo request" + ); + + t.eq( + log.options && log.options.params.BBOX, + "-90,-180,90,180", + "Since it is WMS 1.3 the BBOX should respect axis order" + ); + + } +