Merge pull request #2336 from elemoine/seturl
Add ol.source.TileWMS#setUrls and setUrl
This commit is contained in:
@@ -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
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
@@ -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() {
|
||||
@@ -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();
|
||||
};
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user