Have Layer.WMS support WMS version 1.3 with the axis order sequence, r=elemoine,crschmidt,ahocevar (closes #2284)

git-svn-id: http://svn.openlayers.org/trunk/openlayers@9775 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
bartvde
2009-11-03 14:01:51 +00:00
parent 1e87b26029
commit e003972959
4 changed files with 232 additions and 61 deletions
+52
View File
@@ -0,0 +1,52 @@
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<link rel="stylesheet" href="../theme/default/style.css" type="text/css" />
<link rel="stylesheet" href="style.css" type="text/css" />
<script src="../lib/OpenLayers.js"></script>
<script type="text/javascript">
var map, map2;
function init(){
// clear array to simulate a wrong axis order request
map = new OpenLayers.Map( 'map' );
var layer = new OpenLayers.Layer.WMS(
"OpenLayers WMS",
"http://demo.cubewerx.com/demo/cubeserv/cubeserv.cgi?",
{layers: 'Foundation.GTOPO30', version: '1.3.0'},
{singleTile: true, yx: []}
);
map.addLayer(layer);
map.zoomToMaxExtent();
map2 = new OpenLayers.Map( 'map2' );
var layer2 = new OpenLayers.Layer.WMS(
"OpenLayers WMS",
"http://demo.cubewerx.com/demo/cubeserv/cubeserv.cgi?",
{layers: 'Foundation.GTOPO30', version: '1.3.0'},
{singleTile: true}
);
map2.addLayer(layer2);
map2.zoomToMaxExtent();
}
</script>
</head>
<body onload="init()">
<h1 id="title"> WMS version 1.3 (axis order) Example</h1>
<div id="tags">
</div>
<p id="shortdesc">
Shows an example of the influence of axis order on WMS 1.3 GetMap requests.
</p>
<div id="map" class="smallmap"></div>
<div id="map2" class="smallmap"></div>
<div id="docs">
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.
</div>
</body>
</html>
+20 -9
View File
@@ -128,11 +128,18 @@ OpenLayers.Bounds = OpenLayers.Class({
/** /**
* APIMethod: toArray * APIMethod: toArray
* *
* Parameters:
* reverseAxisOrder - {Boolean} Should we reverse the axis order?
*
* Returns: * Returns:
* {Array} array of left, bottom, right, top * {Array} array of left, bottom, right, top
*/ */
toArray: function() { toArray: function(reverseAxisOrder) {
return [this.left, this.bottom, this.right, this.top]; 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: * Parameters:
* decimal - {Integer} How many significant digits in the bbox coords? * decimal - {Integer} How many significant digits in the bbox coords?
* Default is 6 * Default is 6
* reverseAxisOrder - {Boolean} Should we reverse the axis order?
* *
* Returns: * Returns:
* {String} Simple String representation of bounds object. * {String} Simple String representation of bounds object.
* (ex. <i>"5,42,10,45"</i>) * (ex. <i>"5,42,10,45"</i>)
*/ */
toBBOX:function(decimal) { toBBOX:function(decimal, reverseAxisOrder) {
if (decimal== null) { if (decimal== null) {
decimal = 6; decimal = 6;
} }
var mult = Math.pow(10, decimal); var mult = Math.pow(10, decimal);
var bbox = Math.round(this.left * mult) / mult + "," + var xmin = Math.round(this.left * mult) / mult;
Math.round(this.bottom * mult) / mult + "," + var ymin = Math.round(this.bottom * mult) / mult;
Math.round(this.right * mult) / mult + "," + var xmax = Math.round(this.right * mult) / mult;
Math.round(this.top * mult) / mult; var ymax = Math.round(this.top * mult) / mult;
if (reverseAxisOrder === true) {
return bbox; return ymin + "," + xmin + "," + ymax + "," + xmax;
} else {
return xmin + "," + ymin + "," + xmax + "," + ymax;
}
}, },
/** /**
+28 -6
View File
@@ -64,6 +64,14 @@ OpenLayers.Layer.WMS = OpenLayers.Class(OpenLayers.Layer.Grid, {
*/ */
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 * Constructor: OpenLayers.Layer.WMS
* Create a new WMS layer object * Create a new WMS layer object
@@ -165,11 +173,20 @@ OpenLayers.Layer.WMS = OpenLayers.Class(OpenLayers.Layer.Grid, {
bounds = this.adjustBounds(bounds); bounds = this.adjustBounds(bounds);
var imageSize = this.getImageSize(); var imageSize = this.getImageSize();
var newParams = { var newParams = {};
'BBOX': this.encodeBBOX ? bounds.toBBOX() : bounds.toArray(), // WMS 1.3 introduced axis order
'WIDTH': imageSize.w, if (parseFloat(this.params.VERSION) >= 1.3 &&
'HEIGHT': imageSize.h 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); var requestString = this.getFullRequestString(newParams);
return requestString; return requestString;
}, },
@@ -225,7 +242,12 @@ OpenLayers.Layer.WMS = OpenLayers.Class(OpenLayers.Layer.Grid, {
*/ */
getFullRequestString:function(newParams, altUrl) { getFullRequestString:function(newParams, altUrl) {
var projectionCode = this.map.getProjection(); 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( return OpenLayers.Layer.Grid.prototype.getFullRequestString.apply(
this, arguments); this, arguments);
+86
View File
@@ -398,6 +398,92 @@
t.ok( layer.grid == null, "grid set to null"); t.ok( layer.grid == null, "grid set to null");
} }
function test_Layer_WMS_v13(t) {
t.plan(5);
var lon = 5;
var lat = 40;
var zoom = 5;
var map = new OpenLayers.Map( 'map' );
var layer = new OpenLayers.Layer.WMS(
"OpenLayers WMS",
"http://myserver.org/wms?",
{layers: 'mylayer', version: '1.3.0'},
{singleTile: true}
);
map.addLayer(layer);
map.setCenter(new OpenLayers.LonLat(lon, lat), zoom);
var url = layer.getURL(map.getExtent());
var params = url.split("&");
var bbox;
for (var i=0, len=params.length; i<len; i++) {
var param = params[i];
var a = param.split('=');
if (a[0] === 'BBOX') {
bbox = a[1];
break;
}
}
t.eq(layer.params.CRS, "EPSG:4326", "In WMS 1.3 SRS is now CRS");
t.eq(bbox, "27.9150390625,-5.986328125,52.0849609375,15.986328125", "Axis sequence is lat lon for EPSG:4326 in WMS 1.3.0");
var layer2 = new OpenLayers.Layer.WMS(
"OpenLayers WMS",
"http://myserver.org/wms?",
{layers: 'mylayer', version: '1.1.1'},
{singleTile: true}
);
map.addLayer(layer2);
var url = layer2.getURL(map.getExtent());
var params = url.split("&");
var bbox;
for (var i=0, len=params.length; i<len; i++) {
var param = params[i];
var a = param.split('=');
if (a[0] === 'BBOX') {
bbox = a[1];
break;
}
}
t.eq(layer2.params.SRS, "EPSG:4326", "In WMS 1.1.1 parameter is called SRS");
t.eq(bbox, "-5.986328125,27.9150390625,15.986328125,52.0849609375", "Axis sequence is lon lat for EPSG:4326 in WMS 1.1.1");
map.destroy();
// CRS:84 has normal axis sequence (lon lat)
var map = new OpenLayers.Map( 'map', {projection: 'CRS:84'} );
var layer = new OpenLayers.Layer.WMS(
"OpenLayers WMS",
"http://myserver.org/wms?",
{layers: 'mylayer', version: '1.3.0'},
{singleTile: true}
);
map.addLayer(layer);
map.setCenter(new OpenLayers.LonLat(lon, lat), zoom);
var url = layer.getURL(map.getExtent());
var params = url.split("&");
var bbox;
for (var i=0, len=params.length; i<len; i++) {
var param = params[i];
var a = param.split('=');
if (a[0] === 'BBOX') {
bbox = a[1];
break;
}
}
t.eq(bbox, "-5.986328125,27.9150390625,15.986328125,52.0849609375", "Axis sequence for CRS:84 is lon lat");
map.destroy();
}
</script> </script>
</head> </head>