From e16de02cb2f677a750a832437ec062edcfa6a7f7 Mon Sep 17 00:00:00 2001 From: Olivier Terral Date: Wed, 21 Aug 2013 14:17:49 +0200 Subject: [PATCH] Add getParams/updateParams to TiledWMS --- src/ol/source/tiledwmssource.exports | 2 ++ src/ol/source/tiledwmssource.js | 40 ++++++++++++++++++++++++++-- 2 files changed, 40 insertions(+), 2 deletions(-) diff --git a/src/ol/source/tiledwmssource.exports b/src/ol/source/tiledwmssource.exports index e71fa0bce2..94fb2c22b3 100644 --- a/src/ol/source/tiledwmssource.exports +++ b/src/ol/source/tiledwmssource.exports @@ -1 +1,3 @@ @exportClass ol.source.TileWMS ol.source.TileWMSOptions +@exportProperty ol.source.TileWMS.prototype.getParams +@exportProperty ol.source.TileWMS.prototype.updateParams diff --git a/src/ol/source/tiledwmssource.js b/src/ol/source/tiledwmssource.js index bb5cb54ed3..de94ee02e0 100644 --- a/src/ol/source/tiledwmssource.js +++ b/src/ol/source/tiledwmssource.js @@ -5,6 +5,7 @@ goog.provide('ol.source.TileWMS'); goog.require('goog.array'); goog.require('goog.asserts'); goog.require('goog.math'); +goog.require('goog.object'); goog.require('ol.TileCoord'); goog.require('ol.TileUrlFunction'); goog.require('ol.extent'); @@ -33,12 +34,18 @@ ol.source.TileWMS = function(options) { urls = ol.TileUrlFunction.expandUrl(options.url); } + /** + * @private + * @type {Object} + */ + this.params_ = options.params; + if (goog.isDef(urls)) { var tileUrlFunctions = goog.array.map( urls, function(url) { return ol.TileUrlFunction.createFromParamsFunction( - url, options.params, ol.source.wms.getUrl); - }); + url, this.params_, ol.source.wms.getUrl); + }, this); tileUrlFunction = ol.TileUrlFunction.createFromTileUrlFunctions( tileUrlFunctions); } @@ -97,6 +104,25 @@ ol.source.TileWMS = function(options) { goog.inherits(ol.source.TileWMS, ol.source.TileImage); +/** + * @inheritDoc + */ +ol.source.TileWMS.prototype.getKeyZXY = function(z, x, y) { + return goog.object.getValues(this.params_).join('/') + + goog.base(this, 'getKeyZXY', z, x, y); +}; + + +/** + * Get the user-provided params, i.e. those passed to the constructor through + * the "params" option, and possibly updated using the updateParams method. + * @return {Object} Params. + */ +ol.source.TileWMS.prototype.getParams = function() { + return this.params_; +}; + + /** * @inheritDoc */ @@ -118,3 +144,13 @@ ol.source.TileWMS.prototype.getFeatureInfoForPixel = [pixel[0] - offset[0], pixel[1] - offset[1]], this.getFeatureInfoOptions_, success, opt_error); }; + + +/** + * Update the user-provided params. + * @param {Object} params Params. + */ +ol.source.TileWMS.prototype.updateParams = function(params) { + goog.object.extend(this.params_, params); + this.dispatchChangeEvent(); +};