Skip to content

Commit

Permalink
Merge pull request #2336 from elemoine/seturl
Browse files Browse the repository at this point in the history
Add ol.source.TileWMS#setUrls and setUrl
  • Loading branch information
Éric Lemoine committed Jul 11, 2014
2 parents b518466 + 5fb78fb commit b8c39bd
Showing 1 changed file with 36 additions and 7 deletions.
43 changes: 36 additions & 7 deletions src/ol/source/tilewmssource.js
Expand Up @@ -56,9 +56,9 @@ ol.source.TileWMS = function(opt_options) {

/**
* @private
* @type {Array.<string>|undefined}
* @type {!Array.<string>}
*/
this.urls_ = urls;
this.urls_ = goog.isDefAndNotNull(urls) ? urls : [];

/**
* @private
Expand Down Expand Up @@ -232,7 +232,7 @@ ol.source.TileWMS.prototype.getRequestUrl_ =
pixelRatio, projection, params) {

var urls = this.urls_;
if (!goog.isDef(urls) || goog.array.isEmpty(urls)) {
if (goog.array.isEmpty(urls)) {
return undefined;
}

Expand Down Expand Up @@ -283,7 +283,7 @@ ol.source.TileWMS.prototype.getRequestUrl_ =
if (urls.length == 1) {
url = urls[0];
} else {
var index = goog.math.modulo(tileCoord.hash(), this.urls_.length);
var index = goog.math.modulo(tileCoord.hash(), urls.length);
url = urls[index];
}
return goog.uri.utils.appendParamsFromMap(url, params);
Expand All @@ -309,7 +309,7 @@ ol.source.TileWMS.prototype.getTilePixelSize =

/**
* Return the URLs used for this WMS source.
* @return {Array.<string>|undefined} URLs.
* @return {!Array.<string>} URLs.
* @api
*/
ol.source.TileWMS.prototype.getUrls = function() {
Expand All @@ -323,10 +323,39 @@ ol.source.TileWMS.prototype.getUrls = function() {
ol.source.TileWMS.prototype.resetCoordKeyPrefix_ = function() {
var i = 0;
var res = [];
for (var key in this.params_) {

var j, jj;
for (j = 0, jj = this.urls_.length; j < jj; ++j) {
res[i++] = this.urls_[j];
}

var key;
for (key in this.params_) {
res[i++] = key + '-' + this.params_[key];
}
this.coordKeyPrefix_ = res.join('/');

this.coordKeyPrefix_ = res.join('#');
};


/**
* @param {string|undefined} url URL.
* @api
*/
ol.source.TileWMS.prototype.setUrl = function(url) {
var urls = goog.isDef(url) ? ol.TileUrlFunction.expandUrl(url) : null;
this.setUrls(urls);
};


/**
* @param {Array.<string>|undefined} urls URLs.
* @api
*/
ol.source.TileWMS.prototype.setUrls = function(urls) {
this.urls_ = goog.isDefAndNotNull(urls) ? urls : [];
this.resetCoordKeyPrefix_();
this.dispatchChangeEvent();
};


Expand Down

0 comments on commit b8c39bd

Please sign in to comment.