diff --git a/src/objectliterals.exports b/src/objectliterals.exports index 3f0a1e984d..ce2ad2c57b 100644 --- a/src/objectliterals.exports +++ b/src/objectliterals.exports @@ -111,7 +111,6 @@ @exportObjectLiteralProperty ol.source.SingleImageWMSOptions.projection ol.Projection|undefined @exportObjectLiteralProperty ol.source.SingleImageWMSOptions.resolutions Array.|undefined @exportObjectLiteralProperty ol.source.SingleImageWMSOptions.url string|undefined -@exportObjectLiteralProperty ol.source.SingleImageWMSOptions.version string|undefined @exportObjectLiteral ol.source.StamenOptions @exportObjectLiteralProperty ol.source.StamenOptions.flavor string|undefined @@ -129,11 +128,9 @@ @exportObjectLiteral ol.source.TiledWMSOptions @exportObjectLiteralProperty ol.source.TiledWMSOptions.attributions Array.|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 diff --git a/src/ol/imageurlfunction.js b/src/ol/imageurlfunction.js index 4af4b0a5d2..5bd6ec96a7 100644 --- a/src/ol/imageurlfunction.js +++ b/src/ol/imageurlfunction.js @@ -15,14 +15,13 @@ ol.ImageUrlFunctionType; /** * @param {string} baseUrl Base URL (may have query data). * @param {Object.} 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); }; }; diff --git a/src/ol/source/singleimagewmssource.js b/src/ol/source/singleimagewmssource.js index 0a8ea8d66c..211abdbd36 100644 --- a/src/ol/source/singleimagewmssource.js +++ b/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, { diff --git a/src/ol/source/tiledwmssource.js b/src/ol/source/tiledwmssource.js index 935fac2554..db1315a93e 100644 --- a/src/ol/source/tiledwmssource.js +++ b/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) { diff --git a/src/ol/source/wms.js b/src/ol/source/wms.js index 0fff2f8e25..f076c75c59 100644 --- a/src/ol/source/wms.js +++ b/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); }; diff --git a/src/ol/tileurlfunction.js b/src/ol/tileurlfunction.js index 4e09acc976..3c270b80c6 100644 --- a/src/ol/tileurlfunction.js +++ b/src/ol/tileurlfunction.js @@ -74,11 +74,10 @@ ol.TileUrlFunction.createFromTileUrlFunctions = function(tileUrlFunctions) { /** * @param {string} baseUrl Base URL (may have query data). * @param {Object.} 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); } }; }; diff --git a/test/spec/ol/tileurlfunction.test.js b/test/spec/ol/tileurlfunction.test.js index d411ed4e24..a19f0659fc 100644 --- a/test/spec/ol/tileurlfunction.test.js +++ b/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); }); });