Skip to content
Browse files

WMS GetMap request parameters shall be params

To avoid surprises, we configure everything that is a WMS GetMap
request parameter in the params object, and not as direct
configuration option. This affects the VERSION and TRANSPARENT
params.
  • Loading branch information...
1 parent a912d48 commit c1f3a6cc5461054d7d6dd7a67b32e413ca58e213 @ahocevar ahocevar committed with tschaub
View
3 src/objectliterals.exports
@@ -110,7 +110,6 @@
@exportObjectLiteralProperty ol.source.SingleImageWMSOptions.projection ol.Projection|undefined
@exportObjectLiteralProperty ol.source.SingleImageWMSOptions.resolutions Array.<number>|undefined
@exportObjectLiteralProperty ol.source.SingleImageWMSOptions.url string|undefined
-@exportObjectLiteralProperty ol.source.SingleImageWMSOptions.version string|undefined
@exportObjectLiteral ol.source.SourceOptions
@exportObjectLiteralProperty ol.source.SourceOptions.attributions Array.<ol.Attribution>|undefined
@@ -136,11 +135,9 @@
@exportObjectLiteral ol.source.TiledWMSOptions
@exportObjectLiteralProperty ol.source.TiledWMSOptions.attributions Array.<ol.Attribution>|undefined
@exportObjectLiteralProperty ol.source.TiledWMSOptions.params Object
-@exportObjectLiteralProperty ol.source.TiledWMSOptions.version string|undefined
@exportObjectLiteralProperty ol.source.TiledWMSOptions.crossOrigin null|string|undefined
@exportObjectLiteralProperty ol.source.TiledWMSOptions.extent ol.Extent|undefined
@exportObjectLiteralProperty ol.source.TiledWMSOptions.tileGrid ol.tilegrid.TileGrid|undefined
-@exportObjectLiteralProperty ol.source.TiledWMSOptions.transparent boolean|undefined
@exportObjectLiteralProperty ol.source.TiledWMSOptions.maxZoom number|undefined
@exportObjectLiteralProperty ol.source.TiledWMSOptions.projection ol.Projection|undefined
@exportObjectLiteralProperty ol.source.TiledWMSOptions.url string|undefined
View
5 src/ol/imageurlfunction.js
@@ -15,14 +15,13 @@ ol.ImageUrlFunctionType;
/**
* @param {string} baseUrl Base URL (may have query data).
* @param {Object.<string, string|number>} params WMS parameters.
- * @param {string=} opt_version WMS version.
* @return {ol.ImageUrlFunctionType} Image URL function.
*/
ol.ImageUrlFunction.createWMSParams =
- function(baseUrl, params, opt_version) {
+ function(baseUrl, params) {
return function(extent, size, projection) {
return ol.source.wms.getUrl(
- baseUrl, params, extent, size, projection, opt_version);
+ baseUrl, params, extent, size, projection);
};
};
View
3 src/ol/source/singleimagewmssource.js
@@ -15,8 +15,7 @@ goog.require('ol.source.ImageSource');
*/
ol.source.SingleImageWMS = function(options) {
var imageUrlFunction = goog.isDef(options.url) ?
- ol.ImageUrlFunction.createWMSParams(
- options.url, options.params, options.version) :
+ ol.ImageUrlFunction.createWMSParams(options.url, options.params) :
ol.ImageUrlFunction.nullImageUrlFunction;
goog.base(this, {
View
9 src/ol/source/tiledwmssource.js
@@ -21,25 +21,24 @@ ol.source.TiledWMS = function(tiledWMSOptions) {
if (goog.isDef(tiledWMSOptions.tileGrid)) {
tileGrid = tiledWMSOptions.tileGrid;
}
- var version = tiledWMSOptions.version;
var tileUrlFunction;
if (tiledWMSOptions.urls) {
var tileUrlFunctions = goog.array.map(
tiledWMSOptions.urls, function(url) {
return ol.TileUrlFunction.createWMSParams(
- url, tiledWMSOptions.params, version);
+ url, tiledWMSOptions.params);
});
tileUrlFunction = ol.TileUrlFunction.createFromTileUrlFunctions(
tileUrlFunctions);
} else if (tiledWMSOptions.url) {
tileUrlFunction = ol.TileUrlFunction.createWMSParams(
- tiledWMSOptions.url, tiledWMSOptions.params, version);
+ tiledWMSOptions.url, tiledWMSOptions.params);
} else {
tileUrlFunction = ol.TileUrlFunction.nullTileUrlFunction;
}
- var transparent = goog.isDef(tiledWMSOptions.transparent) ?
- tiledWMSOptions.transparent : true;
+ var transparent = goog.isDef(tiledWMSOptions.params['TRANSPARENT']) ?
+ tiledWMSOptions.params['TRANSPARENT'] : true;
var extent = tiledWMSOptions.extent;
var tileCoordTransform = function(tileCoord, tileGrid, projection) {
View
26 src/ol/source/wms.js
@@ -7,31 +7,33 @@ goog.provide('ol.source.wms');
* @param {ol.Extent} extent Extent.
* @param {ol.Size} size Size.
* @param {ol.Projection} projection Projection.
- * @param {string=} opt_version WMS version. Default is '1.3.0'.
* @return {string} WMS GetMap request URL.
*/
ol.source.wms.getUrl =
- function(baseUrl, params, extent, size, projection, opt_version) {
- var version = goog.isDef(opt_version) ? opt_version : '1.3.0';
- var wms13 = version >= '1.3';
- var axisOrientation = projection.getAxisOrientation();
- var bboxValues = (wms13 && axisOrientation.substr(0, 2) == 'ne') ?
- [extent.minY, extent.minX, extent.maxY, extent.maxX] :
- [extent.minX, extent.minY, extent.maxX, extent.maxY];
+ function(baseUrl, params, extent, size, projection) {
var baseParams = {
'SERVICE': 'WMS',
- 'VERSION': version,
+ 'VERSION': '1.3.0',
'REQUEST': 'GetMap',
'FORMAT': 'image/png',
'TRANSPARENT': true,
'WIDTH': size.width,
- 'HEIGHT': size.height,
- 'BBOX': bboxValues.join(',')
+ 'HEIGHT': size.height
};
goog.object.extend(baseParams, params);
- baseParams[wms13 ? 'CRS' : 'SRS'] = projection.getCode();
+
//TODO: Provide our own appendParams function to avoid this empty string hack
var stylesParam = 'STYLES';
baseParams[stylesParam] = params[stylesParam] || new String('');
+
+ var wms13 = baseParams['VERSION'] > '1.3';
+ baseParams[wms13 ? 'CRS' : 'SRS'] = projection.getCode();
+
+ var axisOrientation = projection.getAxisOrientation();
+ var bboxValues = (wms13 && axisOrientation.substr(0, 2) == 'ne') ?
+ [extent.minY, extent.minX, extent.maxY, extent.maxX] :
+ [extent.minX, extent.minY, extent.maxX, extent.maxY];
+ baseParams['BBOX'] = bboxValues.join(',');
+
return goog.uri.utils.appendParamsFromMap(baseUrl, baseParams);
};
View
5 src/ol/tileurlfunction.js
@@ -74,11 +74,10 @@ ol.TileUrlFunction.createFromTileUrlFunctions = function(tileUrlFunctions) {
/**
* @param {string} baseUrl Base URL (may have query data).
* @param {Object.<string, string|number>} params WMS parameters.
- * @param {string=} opt_version WMS version.
* @return {ol.TileUrlFunctionType} Tile URL function.
*/
ol.TileUrlFunction.createWMSParams =
- function(baseUrl, params, opt_version) {
+ function(baseUrl, params) {
return function(tileCoord, tileGrid, projection) {
if (goog.isNull(tileCoord)) {
return undefined;
@@ -86,7 +85,7 @@ ol.TileUrlFunction.createWMSParams =
var size = tileGrid.getTileSize(tileCoord.z);
var extent = tileGrid.getTileCoordExtent(tileCoord);
return ol.source.wms.getUrl(
- baseUrl, params, extent, size, projection, opt_version);
+ baseUrl, params, extent, size, projection);
}
};
};
View
16 test/spec/ol/tileurlfunction.test.js
@@ -74,10 +74,10 @@ describe('ol.TileUrlFunction', function() {
'http://wms?foo=bar', {});
var tileCoord = new ol.TileCoord(1, 0, 0);
var tileUrl = tileUrlFunction(tileCoord, tileGrid, epsg3857);
- var expected = 'http://wms?foo=bar&SERVICE=WMS&VERSION=1.3.0&' +
- 'REQUEST=GetMap&FORMAT=image%2Fpng&TRANSPARENT=true&WIDTH=256&' +
- 'HEIGHT=256&BBOX=-20037508.342789244%2C20037508.342789244%2C0%2C' +
- '40075016.68557849&CRS=EPSG%3A3857&STYLES=';
+ var expected = 'http://wms?foo=bar&SERVICE=WMS&VERSION=1.3.0&REQUEST=' +
+ 'GetMap&FORMAT=image%2Fpng&TRANSPARENT=true&WIDTH=256&HEIGHT=256&' +
+ 'STYLES=&CRS=EPSG%3A3857&BBOX=-20037508.342789244%2C2' +
+ '0037508.342789244%2C0%2C40075016.68557849';
expect(tileUrl).toEqual(expected);
});
it('creates expected URL respecting axis orientation', function() {
@@ -86,10 +86,10 @@ describe('ol.TileUrlFunction', function() {
'http://wms?foo=bar', {});
var tileCoord = new ol.TileCoord(1, 0, 0);
var tileUrl = tileUrlFunction(tileCoord, tileGrid, epsg4326);
- var expected = 'http://wms?foo=bar&SERVICE=WMS&VERSION=1.3.0&' +
- 'REQUEST=GetMap&FORMAT=image%2Fpng&TRANSPARENT=true&WIDTH=256&' +
- 'HEIGHT=256&BBOX=20037508.342789244%2C-20037508.342789244%2C' +
- '40075016.68557849%2C0&CRS=EPSG%3A4326&STYLES=';
+ var expected = 'http://wms?foo=bar&SERVICE=WMS&VERSION=1.3.0&REQUEST=' +
+ 'GetMap&FORMAT=image%2Fpng&TRANSPARENT=true&WIDTH=256&HEIGHT=256&' +
+ 'STYLES=&CRS=EPSG%3A4326&BBOX=20037508.342789244%2C' +
+ '-20037508.342789244%2C40075016.68557849%2C0';
expect(tileUrl).toEqual(expected);
});
});

0 comments on commit c1f3a6c

Please sign in to comment.
Something went wrong with that request. Please try again.