From 46ca98e48480faa7dedddbddf11880c41039f032 Mon Sep 17 00:00:00 2001 From: ahocevar Date: Wed, 20 Mar 2013 10:45:54 +0100 Subject: [PATCH 1/3] More context for url functions With this change, url functions are called in the scope of the source they are configured for. This allows us to simplify the url function generation for WMS, using a more generic createFromParamsFunction factory, and the source's new params member. Note that there is also a new url member for WMS sources. This is the WMS base url (the first one in case there is an array of urls for faster tile access). This can be used for accessing other WMS services (especially GetFeatureInfo). --- src/ol/imageurlfunction.js | 15 ++++----- src/ol/source/imagesource.js | 2 +- src/ol/source/imagetilesource.js | 3 +- src/ol/source/singleimagewmssource.js | 15 ++++++++- src/ol/source/tiledwmssource.js | 17 ++++++++-- src/ol/source/wms.js | 23 ++++++++++++++ src/ol/tilegrid/tilegrid.js | 1 + src/ol/tileurlfunction.js | 18 +++++------ test/spec/ol/source/wms.test.js | 40 ++++++++++++++++++++++++ test/spec/ol/tileurlfunction.test.js | 45 +++++++++------------------ 10 files changed, 128 insertions(+), 51 deletions(-) create mode 100644 test/spec/ol/source/wms.test.js diff --git a/src/ol/imageurlfunction.js b/src/ol/imageurlfunction.js index 5bd6ec96a7..e6f3849f4a 100644 --- a/src/ol/imageurlfunction.js +++ b/src/ol/imageurlfunction.js @@ -3,25 +3,26 @@ goog.provide('ol.ImageUrlFunctionType'); goog.require('ol.Extent'); goog.require('ol.Size'); -goog.require('ol.source.wms'); /** - * @typedef {function(ol.Extent, ol.Size, ol.Projection): (string|undefined)} + * @typedef {function(this:ol.source.Source, ol.Extent, ol.Size, ol.Projection): + * (string|undefined)} */ ol.ImageUrlFunctionType; /** * @param {string} baseUrl Base URL (may have query data). - * @param {Object.} params WMS parameters. + * @param {function(string, Object., ol.Extent, ol.Size, + * ol.Projection)} paramsFunction params function. * @return {ol.ImageUrlFunctionType} Image URL function. */ -ol.ImageUrlFunction.createWMSParams = - function(baseUrl, params) { +ol.ImageUrlFunction.createFromParamsFunction = + function(baseUrl, paramsFunction) { return function(extent, size, projection) { - return ol.source.wms.getUrl( - baseUrl, params, extent, size, projection); + return paramsFunction( + baseUrl, this.params, extent, size, projection); }; }; diff --git a/src/ol/source/imagesource.js b/src/ol/source/imagesource.js index b96973af8b..060a5c46ce 100644 --- a/src/ol/source/imagesource.js +++ b/src/ol/source/imagesource.js @@ -82,7 +82,7 @@ goog.inherits(ol.source.ImageSource, ol.source.Source); ol.source.ImageSource.prototype.createImage = function(extent, resolution, size, projection) { var image = null; - var imageUrl = this.imageUrlFunction(extent, size, projection); + var imageUrl = this.imageUrlFunction.call(this, extent, size, projection); if (goog.isDef(imageUrl)) { image = new ol.Image( extent, resolution, imageUrl, this.crossOrigin_, diff --git a/src/ol/source/imagetilesource.js b/src/ol/source/imagetilesource.js index 2a6323f634..23a8edb5f3 100644 --- a/src/ol/source/imagetilesource.js +++ b/src/ol/source/imagetilesource.js @@ -94,7 +94,8 @@ ol.source.ImageTileSource.prototype.getTile = } else { goog.asserts.assert(tileGrid); goog.asserts.assert(projection); - var tileUrl = this.tileUrlFunction(tileCoord, tileGrid, projection); + var tileUrl = this.tileUrlFunction.call(this, + tileCoord, tileGrid, projection); var tile = new ol.ImageTile( tileCoord, goog.isDef(tileUrl) ? ol.TileState.IDLE : ol.TileState.EMPTY, diff --git a/src/ol/source/singleimagewmssource.js b/src/ol/source/singleimagewmssource.js index f79591d67f..e622cdf9c3 100644 --- a/src/ol/source/singleimagewmssource.js +++ b/src/ol/source/singleimagewmssource.js @@ -5,17 +5,20 @@ goog.require('ol.Image'); goog.require('ol.ImageUrlFunction'); goog.require('ol.Size'); goog.require('ol.source.ImageSource'); +goog.require('ol.source.wms'); /** * @constructor + * @implements {ol.source.IWMS} * @extends {ol.source.ImageSource} * @param {ol.source.SingleImageWMSOptions} options Options. */ ol.source.SingleImageWMS = function(options) { var imageUrlFunction = goog.isDef(options.url) ? - ol.ImageUrlFunction.createWMSParams(options.url, options.params) : + ol.ImageUrlFunction.createFromParamsFunction( + options.url, ol.source.wms.getUrl) : ol.ImageUrlFunction.nullImageUrlFunction; goog.base(this, { @@ -27,6 +30,16 @@ ol.source.SingleImageWMS = function(options) { imageUrlFunction: imageUrlFunction }); + /** + * @inheritDoc + */ + this.url = options.url; + + /** + * @inheritDoc + */ + this.params = options.params; + /** * @private * @type {ol.Image} diff --git a/src/ol/source/tiledwmssource.js b/src/ol/source/tiledwmssource.js index 6264220212..a34468883b 100644 --- a/src/ol/source/tiledwmssource.js +++ b/src/ol/source/tiledwmssource.js @@ -8,11 +8,13 @@ goog.require('ol.Extent'); goog.require('ol.TileCoord'); goog.require('ol.TileUrlFunction'); goog.require('ol.source.ImageTileSource'); +goog.require('ol.source.wms'); /** * @constructor + * @implements {ol.source.IWMS} * @extends {ol.source.ImageTileSource} * @param {ol.source.TiledWMSOptions} tiledWMSOptions options. */ @@ -30,12 +32,13 @@ ol.source.TiledWMS = function(tiledWMSOptions) { if (goog.isDef(urls)) { var tileUrlFunctions = goog.array.map( urls, function(url) { - return ol.TileUrlFunction.createWMSParams( - url, tiledWMSOptions.params); + return ol.TileUrlFunction.createFromParamsFunction( + url, ol.source.wms.getUrl); }); tileUrlFunction = ol.TileUrlFunction.createFromTileUrlFunctions( tileUrlFunctions); } + var transparent = goog.isDef(tiledWMSOptions.params['TRANSPARENT']) ? tiledWMSOptions.params['TRANSPARENT'] : true; var extent = tiledWMSOptions.extent; @@ -65,6 +68,16 @@ ol.source.TiledWMS = function(tiledWMSOptions) { return new ol.TileCoord(tileCoord.z, x, tileCoord.y); }; + /** + * @inheritDoc + */ + this.url = goog.isDef(urls) ? urls[0] : undefined; + + /** + * @inheritDoc + */ + this.params = tiledWMSOptions.params; + goog.base(this, { attributions: tiledWMSOptions.attributions, crossOrigin: tiledWMSOptions.crossOrigin, diff --git a/src/ol/source/wms.js b/src/ol/source/wms.js index d81e822549..315653b832 100644 --- a/src/ol/source/wms.js +++ b/src/ol/source/wms.js @@ -1,6 +1,29 @@ +goog.provide('ol.source.IWMS'); goog.provide('ol.source.wms'); + +/** + * Interface for WMS + * @interface + */ +ol.source.IWMS = function() {}; + + +/** + * @type {string|undefined} The url for this source. + */ +ol.source.IWMS.prototype.url; + + +/** + * @type {Object.} Parameters for WMS requests. 'LAYERS' is mandatory. + * 'STYLES' defaults to ''. 'VERSION' defaults to '1.3.0'. 'CRS'/'SRS', + * 'BBOX' and 'SIZE' are added dynamically. + */ +ol.source.IWMS.prototype.params; + + /** * @param {string} baseUrl WMS base url. * @param {Object.} params Request parameters. diff --git a/src/ol/tilegrid/tilegrid.js b/src/ol/tilegrid/tilegrid.js index 182b5d7dd3..21a3f38750 100644 --- a/src/ol/tilegrid/tilegrid.js +++ b/src/ol/tilegrid/tilegrid.js @@ -1,5 +1,6 @@ // FIXME cope with tile grids whose minium zoom is not zero +goog.provide('ol.tilegrid'); goog.provide('ol.tilegrid.TileGrid'); goog.require('goog.array'); diff --git a/src/ol/tileurlfunction.js b/src/ol/tileurlfunction.js index f041b5f184..45a884d139 100644 --- a/src/ol/tileurlfunction.js +++ b/src/ol/tileurlfunction.js @@ -4,13 +4,12 @@ goog.provide('ol.TileUrlFunctionType'); goog.require('goog.array'); goog.require('goog.math'); goog.require('ol.TileCoord'); -goog.require('ol.source.wms'); goog.require('ol.tilegrid.TileGrid'); /** - * @typedef {function(ol.TileCoord, ol.tilegrid.TileGrid, ol.Projection): - * (string|undefined)} + * @typedef {function(this:ol.source.Source, ol.TileCoord, ol.tilegrid.TileGrid, + * ol.Projection): (string|undefined)} */ ol.TileUrlFunctionType; @@ -63,19 +62,20 @@ ol.TileUrlFunction.createFromTileUrlFunctions = function(tileUrlFunctions) { /** * @param {string} baseUrl Base URL (may have query data). - * @param {Object.} params WMS parameters. + * @param {function(string, Object., ol.Extent, ol.Size, + * ol.Projection)} paramsFunction params function. * @return {ol.TileUrlFunctionType} Tile URL function. */ -ol.TileUrlFunction.createWMSParams = - function(baseUrl, params) { +ol.TileUrlFunction.createFromParamsFunction = + function(baseUrl, paramsFunction) { return function(tileCoord, tileGrid, projection) { if (goog.isNull(tileCoord)) { return undefined; } else { var size = tileGrid.getTileSize(tileCoord.z); var extent = tileGrid.getTileCoordExtent(tileCoord); - return ol.source.wms.getUrl( - baseUrl, params, extent, size, projection); + return paramsFunction( + baseUrl, this.params, extent, size, projection); } }; }; @@ -102,7 +102,7 @@ ol.TileUrlFunction.withTileCoordTransform = if (goog.isNull(tileCoord)) { return undefined; } else { - return tileUrlFunction( + return tileUrlFunction.call(this, transformFn(tileCoord, tileGrid, projection), tileGrid, projection); } }; diff --git a/test/spec/ol/source/wms.test.js b/test/spec/ol/source/wms.test.js new file mode 100644 index 0000000000..c2d3774965 --- /dev/null +++ b/test/spec/ol/source/wms.test.js @@ -0,0 +1,40 @@ +goog.provide('ol.source.test.wms'); + +describe('ol.source.wms', function() { + + describe('ol.source.wms.getUrl', function() { + var that = {params: {}}; + it('creates expected URL', function() { + var epsg3857 = ol.projection.get('EPSG:3857'); + var tileGrid = ol.tilegrid.getForProjection(epsg3857); + var tileUrlFunction = ol.TileUrlFunction.createFromParamsFunction( + 'http://wms?foo=bar', ol.source.wms.getUrl); + var tileCoord = new ol.TileCoord(1, 0, 0); + var tileUrl = tileUrlFunction.call(that, 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&' + + 'STYLES=&CRS=EPSG%3A3857&BBOX=' + + '-20037508.342789244%2C-20037508.342789244%2C0%2C0'; + expect(tileUrl).to.eql(expected); + }); + it('creates expected URL respecting axis orientation', function() { + var epsg4326 = ol.projection.get('EPSG:4326'); + var tileGrid = ol.tilegrid.getForProjection(epsg4326); + var tileUrlFunction = ol.TileUrlFunction.createFromParamsFunction( + 'http://wms?foo=bar', ol.source.wms.getUrl); + var tileCoord = new ol.TileCoord(1, 0, 0); + var tileUrl = tileUrlFunction.call(that, 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&' + + 'STYLES=&CRS=EPSG%3A4326&BBOX=-90%2C-180%2C90%2C0'; + expect(tileUrl).to.eql(expected); + }); + }); + +}); + + +goog.require('ol.TileCoord'); +goog.require('ol.projection'); +goog.require('ol.source.wms'); +goog.require('ol.tilegrid'); diff --git a/test/spec/ol/tileurlfunction.test.js b/test/spec/ol/tileurlfunction.test.js index 5181df44a7..89380718e8 100644 --- a/test/spec/ol/tileurlfunction.test.js +++ b/test/spec/ol/tileurlfunction.test.js @@ -78,38 +78,23 @@ describe('ol.TileUrlFunction', function() { }); }); - describe('createWMSParams', function() { - var tileGrid; - beforeEach(function() { - tileGrid = new ol.tilegrid.XYZ({ - maxZoom: 10 - }); - }); - it('creates expected URL', function() { - var epsg3857 = ol.projection.get('EPSG:3857'); - var tileUrlFunction = ol.TileUrlFunction.createWMSParams( - '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&' + - 'STYLES=&CRS=EPSG%3A3857&BBOX=-20037508.342789244%2C2' + - '0037508.342789244%2C0%2C40075016.68557849'; - expect(tileUrl).to.eql(expected); - }); - it('creates expected URL respecting axis orientation', function() { - var epsg4326 = ol.projection.get('EPSG:4326'); - var tileUrlFunction = ol.TileUrlFunction.createWMSParams( - '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&' + - 'STYLES=&CRS=EPSG%3A4326&BBOX=20037508.342789244%2C' + - '-20037508.342789244%2C40075016.68557849%2C0'; - expect(tileUrl).to.eql(expected); + describe('createFromParamsFunction', function() { + var paramsFunction = function(url, params) { return arguments; }; + var projection = ol.projection.get('EPSG:3857'); + var tileUrlFunction = ol.TileUrlFunction.createFromParamsFunction( + 'url', paramsFunction); + it('calls the passed function with the correct arguments', function() { + var that = {params: {foo: 'bar'}}; + var args = tileUrlFunction.call(that, new ol.TileCoord(0, 0, 0), + ol.tilegrid.getForProjection(projection), projection); + expect(args[0]).to.eql('url'); + expect(args[1]).to.be(that.params); + expect(args[2]).to.eql(projection.getExtent()); + expect(args[3]).to.eql(new ol.Size(256, 256)); + expect(args[4]).to.eql(projection); }); }); + }); goog.require('ol.TileCoord'); From 57fdd78a19c83cb711e586b23b542290fde306f9 Mon Sep 17 00:00:00 2001 From: ahocevar Date: Wed, 20 Mar 2013 10:55:58 +0100 Subject: [PATCH 2/3] Fixing requires --- src/ol/renderer/canvas/canvastilelayerrenderer.js | 1 + src/ol/renderer/canvas/canvasvectorlayerrenderer.js | 1 + src/ol/renderer/dom/domtilelayerrenderer.js | 1 + src/ol/renderer/webgl/webgltilelayerrenderer.js | 1 + test/spec/ol/source/wms.test.js | 1 + test/spec/ol/tilegrid/tilegrid.test.js | 1 + test/spec/ol/tileurlfunction.test.js | 3 ++- 7 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/ol/renderer/canvas/canvastilelayerrenderer.js b/src/ol/renderer/canvas/canvastilelayerrenderer.js index ac03dd7652..f9ff870658 100644 --- a/src/ol/renderer/canvas/canvastilelayerrenderer.js +++ b/src/ol/renderer/canvas/canvastilelayerrenderer.js @@ -14,6 +14,7 @@ goog.require('ol.TileState'); goog.require('ol.layer.TileLayer'); goog.require('ol.renderer.Map'); goog.require('ol.renderer.canvas.Layer'); +goog.require('ol.tilegrid'); diff --git a/src/ol/renderer/canvas/canvasvectorlayerrenderer.js b/src/ol/renderer/canvas/canvasvectorlayerrenderer.js index 41e1b56c31..ca4d7ed9ad 100644 --- a/src/ol/renderer/canvas/canvasvectorlayerrenderer.js +++ b/src/ol/renderer/canvas/canvasvectorlayerrenderer.js @@ -14,6 +14,7 @@ goog.require('ol.geom.GeometryType'); goog.require('ol.layer.Vector'); goog.require('ol.renderer.canvas.Layer'); goog.require('ol.renderer.canvas.VectorRenderer'); +goog.require('ol.tilegrid'); goog.require('ol.tilegrid.TileGrid'); diff --git a/src/ol/renderer/dom/domtilelayerrenderer.js b/src/ol/renderer/dom/domtilelayerrenderer.js index a3d99ff47d..1c3c38ea7b 100644 --- a/src/ol/renderer/dom/domtilelayerrenderer.js +++ b/src/ol/renderer/dom/domtilelayerrenderer.js @@ -16,6 +16,7 @@ goog.require('ol.ViewHint'); goog.require('ol.dom'); goog.require('ol.layer.TileLayer'); goog.require('ol.renderer.dom.Layer'); +goog.require('ol.tilegrid'); goog.require('ol.tilegrid.TileGrid'); diff --git a/src/ol/renderer/webgl/webgltilelayerrenderer.js b/src/ol/renderer/webgl/webgltilelayerrenderer.js index ff586257fc..53616f2c4e 100644 --- a/src/ol/renderer/webgl/webgltilelayerrenderer.js +++ b/src/ol/renderer/webgl/webgltilelayerrenderer.js @@ -23,6 +23,7 @@ goog.require('ol.layer.TileLayer'); goog.require('ol.renderer.webgl.FragmentShader'); goog.require('ol.renderer.webgl.Layer'); goog.require('ol.renderer.webgl.VertexShader'); +goog.require('ol.tilegrid'); diff --git a/test/spec/ol/source/wms.test.js b/test/spec/ol/source/wms.test.js index c2d3774965..a437be4e17 100644 --- a/test/spec/ol/source/wms.test.js +++ b/test/spec/ol/source/wms.test.js @@ -35,6 +35,7 @@ describe('ol.source.wms', function() { goog.require('ol.TileCoord'); +goog.require('ol.TileUrlFunction'); goog.require('ol.projection'); goog.require('ol.source.wms'); goog.require('ol.tilegrid'); diff --git a/test/spec/ol/tilegrid/tilegrid.test.js b/test/spec/ol/tilegrid/tilegrid.test.js index 507b170a8d..9cf0b7add6 100644 --- a/test/spec/ol/tilegrid/tilegrid.test.js +++ b/test/spec/ol/tilegrid/tilegrid.test.js @@ -660,4 +660,5 @@ goog.require('ol.Extent'); goog.require('ol.Size'); goog.require('ol.TileCoord'); goog.require('ol.projection'); +goog.require('ol.tilegrid'); goog.require('ol.tilegrid.TileGrid'); diff --git a/test/spec/ol/tileurlfunction.test.js b/test/spec/ol/tileurlfunction.test.js index 89380718e8..9e6b58f67a 100644 --- a/test/spec/ol/tileurlfunction.test.js +++ b/test/spec/ol/tileurlfunction.test.js @@ -97,7 +97,8 @@ describe('ol.TileUrlFunction', function() { }); +goog.require('ol.Size'); goog.require('ol.TileCoord'); goog.require('ol.TileUrlFunction'); goog.require('ol.projection'); -goog.require('ol.tilegrid.XYZ'); +goog.require('ol.tilegrid'); From 5719160155ce82c87123f92d2ca8e8b6d61b0fe3 Mon Sep 17 00:00:00 2001 From: ahocevar Date: Wed, 20 Mar 2013 13:41:36 +0100 Subject: [PATCH 3/3] Less context This change removes all changes that were anticipated here for WMS GetFeatureInfo handling, including the IWMS interface and the goog.provide for 'ol.tilegrid'. I'll create a separate pull request for WMS GetFeatureInfo eventually, taking into account the suggestions from the discussion in #402. --- src/ol/imageurlfunction.js | 5 ++-- .../canvas/canvastilelayerrenderer.js | 1 - .../canvas/canvasvectorlayerrenderer.js | 1 - src/ol/renderer/dom/domtilelayerrenderer.js | 1 - .../renderer/webgl/webgltilelayerrenderer.js | 1 - src/ol/source/imagesource.js | 2 +- src/ol/source/imagetilesource.js | 3 +-- src/ol/source/singleimagewmssource.js | 13 +---------- src/ol/source/tiledwmssource.js | 13 +---------- src/ol/source/wms.js | 23 ------------------- src/ol/tilegrid/tilegrid.js | 1 - src/ol/tileurlfunction.js | 5 ++-- test/spec/ol/source/wms.test.js | 18 +++++++-------- test/spec/ol/tilegrid/tilegrid.test.js | 1 - test/spec/ol/tileurlfunction.test.js | 9 ++++---- 15 files changed, 22 insertions(+), 75 deletions(-) diff --git a/src/ol/imageurlfunction.js b/src/ol/imageurlfunction.js index e6f3849f4a..9f52622858 100644 --- a/src/ol/imageurlfunction.js +++ b/src/ol/imageurlfunction.js @@ -14,15 +14,16 @@ ol.ImageUrlFunctionType; /** * @param {string} baseUrl Base URL (may have query data). + * @param {Object.} params to encode in the url. * @param {function(string, Object., ol.Extent, ol.Size, * ol.Projection)} paramsFunction params function. * @return {ol.ImageUrlFunctionType} Image URL function. */ ol.ImageUrlFunction.createFromParamsFunction = - function(baseUrl, paramsFunction) { + function(baseUrl, params, paramsFunction) { return function(extent, size, projection) { return paramsFunction( - baseUrl, this.params, extent, size, projection); + baseUrl, params, extent, size, projection); }; }; diff --git a/src/ol/renderer/canvas/canvastilelayerrenderer.js b/src/ol/renderer/canvas/canvastilelayerrenderer.js index f9ff870658..ac03dd7652 100644 --- a/src/ol/renderer/canvas/canvastilelayerrenderer.js +++ b/src/ol/renderer/canvas/canvastilelayerrenderer.js @@ -14,7 +14,6 @@ goog.require('ol.TileState'); goog.require('ol.layer.TileLayer'); goog.require('ol.renderer.Map'); goog.require('ol.renderer.canvas.Layer'); -goog.require('ol.tilegrid'); diff --git a/src/ol/renderer/canvas/canvasvectorlayerrenderer.js b/src/ol/renderer/canvas/canvasvectorlayerrenderer.js index ca4d7ed9ad..41e1b56c31 100644 --- a/src/ol/renderer/canvas/canvasvectorlayerrenderer.js +++ b/src/ol/renderer/canvas/canvasvectorlayerrenderer.js @@ -14,7 +14,6 @@ goog.require('ol.geom.GeometryType'); goog.require('ol.layer.Vector'); goog.require('ol.renderer.canvas.Layer'); goog.require('ol.renderer.canvas.VectorRenderer'); -goog.require('ol.tilegrid'); goog.require('ol.tilegrid.TileGrid'); diff --git a/src/ol/renderer/dom/domtilelayerrenderer.js b/src/ol/renderer/dom/domtilelayerrenderer.js index 1c3c38ea7b..a3d99ff47d 100644 --- a/src/ol/renderer/dom/domtilelayerrenderer.js +++ b/src/ol/renderer/dom/domtilelayerrenderer.js @@ -16,7 +16,6 @@ goog.require('ol.ViewHint'); goog.require('ol.dom'); goog.require('ol.layer.TileLayer'); goog.require('ol.renderer.dom.Layer'); -goog.require('ol.tilegrid'); goog.require('ol.tilegrid.TileGrid'); diff --git a/src/ol/renderer/webgl/webgltilelayerrenderer.js b/src/ol/renderer/webgl/webgltilelayerrenderer.js index 53616f2c4e..ff586257fc 100644 --- a/src/ol/renderer/webgl/webgltilelayerrenderer.js +++ b/src/ol/renderer/webgl/webgltilelayerrenderer.js @@ -23,7 +23,6 @@ goog.require('ol.layer.TileLayer'); goog.require('ol.renderer.webgl.FragmentShader'); goog.require('ol.renderer.webgl.Layer'); goog.require('ol.renderer.webgl.VertexShader'); -goog.require('ol.tilegrid'); diff --git a/src/ol/source/imagesource.js b/src/ol/source/imagesource.js index 060a5c46ce..b96973af8b 100644 --- a/src/ol/source/imagesource.js +++ b/src/ol/source/imagesource.js @@ -82,7 +82,7 @@ goog.inherits(ol.source.ImageSource, ol.source.Source); ol.source.ImageSource.prototype.createImage = function(extent, resolution, size, projection) { var image = null; - var imageUrl = this.imageUrlFunction.call(this, extent, size, projection); + var imageUrl = this.imageUrlFunction(extent, size, projection); if (goog.isDef(imageUrl)) { image = new ol.Image( extent, resolution, imageUrl, this.crossOrigin_, diff --git a/src/ol/source/imagetilesource.js b/src/ol/source/imagetilesource.js index 23a8edb5f3..2a6323f634 100644 --- a/src/ol/source/imagetilesource.js +++ b/src/ol/source/imagetilesource.js @@ -94,8 +94,7 @@ ol.source.ImageTileSource.prototype.getTile = } else { goog.asserts.assert(tileGrid); goog.asserts.assert(projection); - var tileUrl = this.tileUrlFunction.call(this, - tileCoord, tileGrid, projection); + var tileUrl = this.tileUrlFunction(tileCoord, tileGrid, projection); var tile = new ol.ImageTile( tileCoord, goog.isDef(tileUrl) ? ol.TileState.IDLE : ol.TileState.EMPTY, diff --git a/src/ol/source/singleimagewmssource.js b/src/ol/source/singleimagewmssource.js index e622cdf9c3..ec4f9a199d 100644 --- a/src/ol/source/singleimagewmssource.js +++ b/src/ol/source/singleimagewmssource.js @@ -11,14 +11,13 @@ goog.require('ol.source.wms'); /** * @constructor - * @implements {ol.source.IWMS} * @extends {ol.source.ImageSource} * @param {ol.source.SingleImageWMSOptions} options Options. */ ol.source.SingleImageWMS = function(options) { var imageUrlFunction = goog.isDef(options.url) ? ol.ImageUrlFunction.createFromParamsFunction( - options.url, ol.source.wms.getUrl) : + options.url, options.params, ol.source.wms.getUrl) : ol.ImageUrlFunction.nullImageUrlFunction; goog.base(this, { @@ -30,16 +29,6 @@ ol.source.SingleImageWMS = function(options) { imageUrlFunction: imageUrlFunction }); - /** - * @inheritDoc - */ - this.url = options.url; - - /** - * @inheritDoc - */ - this.params = options.params; - /** * @private * @type {ol.Image} diff --git a/src/ol/source/tiledwmssource.js b/src/ol/source/tiledwmssource.js index a34468883b..d719aab9a0 100644 --- a/src/ol/source/tiledwmssource.js +++ b/src/ol/source/tiledwmssource.js @@ -14,7 +14,6 @@ goog.require('ol.source.wms'); /** * @constructor - * @implements {ol.source.IWMS} * @extends {ol.source.ImageTileSource} * @param {ol.source.TiledWMSOptions} tiledWMSOptions options. */ @@ -33,7 +32,7 @@ ol.source.TiledWMS = function(tiledWMSOptions) { var tileUrlFunctions = goog.array.map( urls, function(url) { return ol.TileUrlFunction.createFromParamsFunction( - url, ol.source.wms.getUrl); + url, tiledWMSOptions.params, ol.source.wms.getUrl); }); tileUrlFunction = ol.TileUrlFunction.createFromTileUrlFunctions( tileUrlFunctions); @@ -68,16 +67,6 @@ ol.source.TiledWMS = function(tiledWMSOptions) { return new ol.TileCoord(tileCoord.z, x, tileCoord.y); }; - /** - * @inheritDoc - */ - this.url = goog.isDef(urls) ? urls[0] : undefined; - - /** - * @inheritDoc - */ - this.params = tiledWMSOptions.params; - goog.base(this, { attributions: tiledWMSOptions.attributions, crossOrigin: tiledWMSOptions.crossOrigin, diff --git a/src/ol/source/wms.js b/src/ol/source/wms.js index 315653b832..d81e822549 100644 --- a/src/ol/source/wms.js +++ b/src/ol/source/wms.js @@ -1,29 +1,6 @@ -goog.provide('ol.source.IWMS'); goog.provide('ol.source.wms'); - -/** - * Interface for WMS - * @interface - */ -ol.source.IWMS = function() {}; - - -/** - * @type {string|undefined} The url for this source. - */ -ol.source.IWMS.prototype.url; - - -/** - * @type {Object.} Parameters for WMS requests. 'LAYERS' is mandatory. - * 'STYLES' defaults to ''. 'VERSION' defaults to '1.3.0'. 'CRS'/'SRS', - * 'BBOX' and 'SIZE' are added dynamically. - */ -ol.source.IWMS.prototype.params; - - /** * @param {string} baseUrl WMS base url. * @param {Object.} params Request parameters. diff --git a/src/ol/tilegrid/tilegrid.js b/src/ol/tilegrid/tilegrid.js index 21a3f38750..182b5d7dd3 100644 --- a/src/ol/tilegrid/tilegrid.js +++ b/src/ol/tilegrid/tilegrid.js @@ -1,6 +1,5 @@ // FIXME cope with tile grids whose minium zoom is not zero -goog.provide('ol.tilegrid'); goog.provide('ol.tilegrid.TileGrid'); goog.require('goog.array'); diff --git a/src/ol/tileurlfunction.js b/src/ol/tileurlfunction.js index 45a884d139..a586fe9ca7 100644 --- a/src/ol/tileurlfunction.js +++ b/src/ol/tileurlfunction.js @@ -62,12 +62,13 @@ ol.TileUrlFunction.createFromTileUrlFunctions = function(tileUrlFunctions) { /** * @param {string} baseUrl Base URL (may have query data). + * @param {Object.} params to encode in the url. * @param {function(string, Object., ol.Extent, ol.Size, * ol.Projection)} paramsFunction params function. * @return {ol.TileUrlFunctionType} Tile URL function. */ ol.TileUrlFunction.createFromParamsFunction = - function(baseUrl, paramsFunction) { + function(baseUrl, params, paramsFunction) { return function(tileCoord, tileGrid, projection) { if (goog.isNull(tileCoord)) { return undefined; @@ -75,7 +76,7 @@ ol.TileUrlFunction.createFromParamsFunction = var size = tileGrid.getTileSize(tileCoord.z); var extent = tileGrid.getTileCoordExtent(tileCoord); return paramsFunction( - baseUrl, this.params, extent, size, projection); + baseUrl, params, extent, size, projection); } }; }; diff --git a/test/spec/ol/source/wms.test.js b/test/spec/ol/source/wms.test.js index a437be4e17..8553c6fe1a 100644 --- a/test/spec/ol/source/wms.test.js +++ b/test/spec/ol/source/wms.test.js @@ -3,17 +3,16 @@ goog.provide('ol.source.test.wms'); describe('ol.source.wms', function() { describe('ol.source.wms.getUrl', function() { - var that = {params: {}}; it('creates expected URL', function() { var epsg3857 = ol.projection.get('EPSG:3857'); var tileGrid = ol.tilegrid.getForProjection(epsg3857); var tileUrlFunction = ol.TileUrlFunction.createFromParamsFunction( - 'http://wms?foo=bar', ol.source.wms.getUrl); + 'http://wms', {'foo': 'bar'}, ol.source.wms.getUrl); var tileCoord = new ol.TileCoord(1, 0, 0); - var tileUrl = tileUrlFunction.call(that, tileCoord, tileGrid, epsg3857); - var expected = 'http://wms?foo=bar&SERVICE=WMS&VERSION=1.3.0&REQUEST=' + + var tileUrl = tileUrlFunction(tileCoord, tileGrid, epsg3857); + var expected = 'http://wms?SERVICE=WMS&VERSION=1.3.0&REQUEST=' + 'GetMap&FORMAT=image%2Fpng&TRANSPARENT=true&WIDTH=256&HEIGHT=256&' + - 'STYLES=&CRS=EPSG%3A3857&BBOX=' + + 'foo=bar&STYLES=&CRS=EPSG%3A3857&BBOX=' + '-20037508.342789244%2C-20037508.342789244%2C0%2C0'; expect(tileUrl).to.eql(expected); }); @@ -21,12 +20,12 @@ describe('ol.source.wms', function() { var epsg4326 = ol.projection.get('EPSG:4326'); var tileGrid = ol.tilegrid.getForProjection(epsg4326); var tileUrlFunction = ol.TileUrlFunction.createFromParamsFunction( - 'http://wms?foo=bar', ol.source.wms.getUrl); + 'http://wms', {'foo': 'bar'}, ol.source.wms.getUrl); var tileCoord = new ol.TileCoord(1, 0, 0); - var tileUrl = tileUrlFunction.call(that, tileCoord, tileGrid, epsg4326); - var expected = 'http://wms?foo=bar&SERVICE=WMS&VERSION=1.3.0&REQUEST=' + + var tileUrl = tileUrlFunction(tileCoord, tileGrid, epsg4326); + var expected = 'http://wms?SERVICE=WMS&VERSION=1.3.0&REQUEST=' + 'GetMap&FORMAT=image%2Fpng&TRANSPARENT=true&WIDTH=256&HEIGHT=256&' + - 'STYLES=&CRS=EPSG%3A4326&BBOX=-90%2C-180%2C90%2C0'; + 'foo=bar&STYLES=&CRS=EPSG%3A4326&BBOX=-90%2C-180%2C90%2C0'; expect(tileUrl).to.eql(expected); }); }); @@ -38,4 +37,3 @@ goog.require('ol.TileCoord'); goog.require('ol.TileUrlFunction'); goog.require('ol.projection'); goog.require('ol.source.wms'); -goog.require('ol.tilegrid'); diff --git a/test/spec/ol/tilegrid/tilegrid.test.js b/test/spec/ol/tilegrid/tilegrid.test.js index 9cf0b7add6..507b170a8d 100644 --- a/test/spec/ol/tilegrid/tilegrid.test.js +++ b/test/spec/ol/tilegrid/tilegrid.test.js @@ -660,5 +660,4 @@ goog.require('ol.Extent'); goog.require('ol.Size'); goog.require('ol.TileCoord'); goog.require('ol.projection'); -goog.require('ol.tilegrid'); goog.require('ol.tilegrid.TileGrid'); diff --git a/test/spec/ol/tileurlfunction.test.js b/test/spec/ol/tileurlfunction.test.js index 9e6b58f67a..6b5bd490d8 100644 --- a/test/spec/ol/tileurlfunction.test.js +++ b/test/spec/ol/tileurlfunction.test.js @@ -81,14 +81,14 @@ describe('ol.TileUrlFunction', function() { describe('createFromParamsFunction', function() { var paramsFunction = function(url, params) { return arguments; }; var projection = ol.projection.get('EPSG:3857'); + var params = {foo: 'bar'}; var tileUrlFunction = ol.TileUrlFunction.createFromParamsFunction( - 'url', paramsFunction); + 'url', params, paramsFunction); it('calls the passed function with the correct arguments', function() { - var that = {params: {foo: 'bar'}}; - var args = tileUrlFunction.call(that, new ol.TileCoord(0, 0, 0), + var args = tileUrlFunction(new ol.TileCoord(0, 0, 0), ol.tilegrid.getForProjection(projection), projection); expect(args[0]).to.eql('url'); - expect(args[1]).to.be(that.params); + expect(args[1]).to.be(params); expect(args[2]).to.eql(projection.getExtent()); expect(args[3]).to.eql(new ol.Size(256, 256)); expect(args[4]).to.eql(projection); @@ -101,4 +101,3 @@ goog.require('ol.Size'); goog.require('ol.TileCoord'); goog.require('ol.TileUrlFunction'); goog.require('ol.projection'); -goog.require('ol.tilegrid');