More robust coordinate keys for WMTS and TiledWMS
This uses more robust ZXY coordinate keys, and caches the key to avoid creating garbage each time getKeyZXY is called.
This commit is contained in:
1 parent
0823ee4ad3
commit
31cc1f5541
2 files changed
+44
-4
No files matched your search
@@ -40,6 +40,13 @@ ol.source.TileWMS = function(options) {
|
||||
*/
|
||||
this.params_ = options.params;
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {string}
|
||||
*/
|
||||
this.coordKeyPrefix_ = '';
|
||||
this.resetCoordKeyPrefix_();
|
||||
|
||||
if (goog.isDef(urls)) {
|
||||
var tileUrlFunctions = goog.array.map(
|
||||
urls, function(url) {
|
||||
@@ -108,8 +115,7 @@ 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);
|
||||
return this.coordKeyPrefix_ + goog.base(this, 'getKeyZXY', z, x, y);
|
||||
};
|
||||
|
||||
|
||||
@@ -146,11 +152,25 @@ ol.source.TileWMS.prototype.getFeatureInfoForPixel =
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
ol.source.TileWMS.prototype.resetCoordKeyPrefix_ = function() {
|
||||
var i = 0;
|
||||
var res = [];
|
||||
for (var key in this.params_) {
|
||||
res[i++] = key + '-' + this.params_[key];
|
||||
}
|
||||
this.coordKeyPrefix_ = res.join('/');
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Update the user-provided params.
|
||||
* @param {Object} params Params.
|
||||
*/
|
||||
ol.source.TileWMS.prototype.updateParams = function(params) {
|
||||
goog.object.extend(this.params_, params);
|
||||
this.resetCoordKeyPrefix_();
|
||||
this.dispatchChangeEvent();
|
||||
};
|
||||
@@ -43,6 +43,13 @@ ol.source.WMTS = function(options) {
|
||||
*/
|
||||
this.dimensions_ = options.dimensions || {};
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {string}
|
||||
*/
|
||||
this.coordKeyPrefix_ = '';
|
||||
this.resetCoordKeyPrefix_();
|
||||
|
||||
// FIXME: should we guess this requestEncoding from options.url(s)
|
||||
// structure? that would mean KVP only if a template is not provided.
|
||||
var requestEncoding = goog.isDef(options.requestEncoding) ?
|
||||
@@ -192,8 +199,20 @@ ol.source.WMTS.prototype.getDimensions = function() {
|
||||
* @inheritDoc
|
||||
*/
|
||||
ol.source.WMTS.prototype.getKeyZXY = function(z, x, y) {
|
||||
return goog.object.getValues(this.dimensions_).join('/') +
|
||||
goog.base(this, 'getKeyZXY', z, x, y);
|
||||
return this.coordKeyPrefix_ + goog.base(this, 'getKeyZXY', z, x, y);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
ol.source.WMTS.prototype.resetCoordKeyPrefix_ = function() {
|
||||
var i = 0;
|
||||
var res = [];
|
||||
for (var key in this.dimensions_) {
|
||||
res[i++] = key + '-' + this.dimensions_[key];
|
||||
}
|
||||
this.coordKeyPrefix_ = res.join('/');
|
||||
};
|
||||
|
||||
|
||||
@@ -203,6 +222,7 @@ ol.source.WMTS.prototype.getKeyZXY = function(z, x, y) {
|
||||
*/
|
||||
ol.source.WMTS.prototype.updateDimensions = function(dimensions) {
|
||||
goog.object.extend(this.dimensions_, dimensions);
|
||||
this.resetCoordKeyPrefix_();
|
||||
this.dispatchChangeEvent();
|
||||
};
|
||||
|
||||
|
||||
Reference in new issue
Block a user