make WMSGetFeatureInfo Control WMS 1.3 compatible, r=ahocevar (closes #2355)

git-svn-id: http://svn.openlayers.org/trunk/openlayers@9879 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
bartvde
2009-12-09 19:08:55 +00:00
parent f28ebc2a02
commit fdb924ebfb
3 changed files with 102 additions and 32 deletions

View File

@@ -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]));
}
return {
url: url,
params: OpenLayers.Util.applyDefaults({
var params = OpenLayers.Util.extend({
service: "WMS",
version: "1.1.0",
version: layers[0].params.VERSION,
request: "GetFeatureInfo",
layers: layerNames,
query_layers: layerNames,
styles: styleNames,
bbox: this.map.getExtent().toBBOX(),
srs: this.map.getProjection(),
bbox: this.map.getExtent().toBBOX(null,
layers[0].reverseAxisOrder()),
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),
}, (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.upperCaseObject(params),
callback: function(request) {
this.handleResponse(clickPosition, request);
},

View File

@@ -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);

View File

@@ -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"
);
}
</script>
</head>
<body>