diff --git a/examples/wms-v13.html b/examples/wms-v13.html new file mode 100644 index 0000000000..11909a517b --- /dev/null +++ b/examples/wms-v13.html @@ -0,0 +1,52 @@ + + + + + + + + +

WMS version 1.3 (axis order) Example

+ +
+
+

+ Shows an example of the influence of axis order on WMS 1.3 GetMap requests. +

+
+
+
+ WMS version 1.3 introduced the axis order sequence, so that for e.g. EPSG:4326 the bbox coordinate + values need to be flipped (LatLon instead of LonLat). The first map uses the incorrect (WMS 1.1) axis + order against a WMS 1.3 service, resulting in corrupted maps. The second map shows how to correctly + request a map in EPSG:4326 against a WMS 1.3 service. +
+ + diff --git a/lib/OpenLayers/BaseTypes/Bounds.js b/lib/OpenLayers/BaseTypes/Bounds.js index 747ce827cf..f4bbad1120 100644 --- a/lib/OpenLayers/BaseTypes/Bounds.js +++ b/lib/OpenLayers/BaseTypes/Bounds.js @@ -128,11 +128,18 @@ OpenLayers.Bounds = OpenLayers.Class({ /** * APIMethod: toArray * + * Parameters: + * reverseAxisOrder - {Boolean} Should we reverse the axis order? + * * Returns: * {Array} array of left, bottom, right, top */ - toArray: function() { - return [this.left, this.bottom, this.right, this.top]; + toArray: function(reverseAxisOrder) { + if (reverseAxisOrder === true) { + return [this.bottom, this.left, this.top, this.right]; + } else { + return [this.left, this.bottom, this.right, this.top]; + } }, /** @@ -141,22 +148,26 @@ OpenLayers.Bounds = OpenLayers.Class({ * Parameters: * decimal - {Integer} How many significant digits in the bbox coords? * Default is 6 + * reverseAxisOrder - {Boolean} Should we reverse the axis order? * * Returns: * {String} Simple String representation of bounds object. * (ex. "5,42,10,45") */ - toBBOX:function(decimal) { + toBBOX:function(decimal, reverseAxisOrder) { if (decimal== null) { decimal = 6; } var mult = Math.pow(10, decimal); - var bbox = Math.round(this.left * mult) / mult + "," + - Math.round(this.bottom * mult) / mult + "," + - Math.round(this.right * mult) / mult + "," + - Math.round(this.top * mult) / mult; - - return bbox; + var xmin = Math.round(this.left * mult) / mult; + var ymin = Math.round(this.bottom * mult) / mult; + var xmax = Math.round(this.right * mult) / mult; + var ymax = Math.round(this.top * mult) / mult; + if (reverseAxisOrder === true) { + return ymin + "," + xmin + "," + ymax + "," + xmax; + } else { + return xmin + "," + ymin + "," + xmax + "," + ymax; + } }, /** diff --git a/lib/OpenLayers/Layer/WMS.js b/lib/OpenLayers/Layer/WMS.js index a564df6f41..1fb4f87398 100644 --- a/lib/OpenLayers/Layer/WMS.js +++ b/lib/OpenLayers/Layer/WMS.js @@ -62,7 +62,15 @@ OpenLayers.Layer.WMS = OpenLayers.Class(OpenLayers.Layer.Grid, { * TRANSPARENT=TRUE. Also isBaseLayer will not changed by the * constructor. Default false. */ - noMagic: false, + noMagic: false, + + /** + * Property: yx + * {Array} Array of strings with the EPSG codes for which the axis order + * is to be reversed (yx instead of xy, LatLon instead of LonLat). This + * is only relevant for WMS versions >= 1.3.0. + */ + yx: ['EPSG:4326'], /** * Constructor: OpenLayers.Layer.WMS @@ -164,12 +172,21 @@ OpenLayers.Layer.WMS = OpenLayers.Class(OpenLayers.Layer.Grid, { getURL: function (bounds) { bounds = this.adjustBounds(bounds); - var imageSize = this.getImageSize(); - var newParams = { - 'BBOX': this.encodeBBOX ? bounds.toBBOX() : bounds.toArray(), - 'WIDTH': imageSize.w, - 'HEIGHT': imageSize.h - }; + 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(); + } + newParams.WIDTH = imageSize.w; + newParams.HEIGHT = imageSize.h; var requestString = this.getFullRequestString(newParams); return requestString; }, @@ -225,7 +242,12 @@ OpenLayers.Layer.WMS = OpenLayers.Class(OpenLayers.Layer.Grid, { */ getFullRequestString:function(newParams, altUrl) { var projectionCode = this.map.getProjection(); - this.params.SRS = (projectionCode == "none") ? null : projectionCode; + var value = (projectionCode == "none") ? null : projectionCode + if (parseFloat(this.params.VERSION) >= 1.3) { + this.params.CRS = value; + } else { + this.params.SRS = value; + } return OpenLayers.Layer.Grid.prototype.getFullRequestString.apply( this, arguments); diff --git a/tests/Layer/WMS.html b/tests/Layer/WMS.html index ee8c743a2d..7b2de35e4e 100644 --- a/tests/Layer/WMS.html +++ b/tests/Layer/WMS.html @@ -6,20 +6,20 @@