Add getDimensions/updateDimensions to WMTS
This commit is contained in:
@@ -36,7 +36,12 @@ ol.source.WMTS = function(options) {
|
||||
|
||||
var version = goog.isDef(options.version) ? options.version : '1.0.0';
|
||||
var format = goog.isDef(options.format) ? options.format : 'image/jpeg';
|
||||
var dimensions = options.dimensions || {};
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {Object}
|
||||
*/
|
||||
this.dimensions_ = options.dimensions || {};
|
||||
|
||||
// FIXME: should we guess this requestEncoding from options.url(s)
|
||||
// structure? that would mean KVP only if a template is not provided.
|
||||
@@ -53,19 +58,14 @@ ol.source.WMTS = function(options) {
|
||||
'Style': options.style,
|
||||
'TileMatrixSet': options.matrixSet
|
||||
};
|
||||
goog.object.extend(context, dimensions);
|
||||
var kvpParams;
|
||||
|
||||
if (requestEncoding == ol.source.WMTSRequestEncoding.KVP) {
|
||||
kvpParams = {
|
||||
goog.object.extend(context, {
|
||||
'Service': 'WMTS',
|
||||
'Request': 'GetTile',
|
||||
'Version': version,
|
||||
'Format': format,
|
||||
'TileMatrix': '{TileMatrix}',
|
||||
'TileRow': '{TileRow}',
|
||||
'TileCol': '{TileCol}'
|
||||
};
|
||||
goog.object.extend(kvpParams, context);
|
||||
'Format': format
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -73,6 +73,17 @@ ol.source.WMTS = function(options) {
|
||||
* @return {ol.TileUrlFunctionType} Tile URL function.
|
||||
*/
|
||||
function createFromWMTSTemplate(template) {
|
||||
|
||||
// TODO: we may want to create our own appendParams function so that params
|
||||
// order conforms to wmts spec guidance, and so that we can avoid to escape
|
||||
// special template params
|
||||
|
||||
template = (requestEncoding == ol.source.WMTSRequestEncoding.KVP) ?
|
||||
goog.uri.utils.appendParamsFromMap(template, context) :
|
||||
template.replace(/\{(\w+?)\}/g, function(m, p) {
|
||||
return (p in context) ? context[p] : m;
|
||||
});
|
||||
|
||||
return (
|
||||
/**
|
||||
* @this {ol.source.WMTS}
|
||||
@@ -89,13 +100,14 @@ ol.source.WMTS = function(options) {
|
||||
'TileCol': tileCoord.x,
|
||||
'TileRow': tileCoord.y
|
||||
};
|
||||
if (requestEncoding != ol.source.WMTSRequestEncoding.KVP) {
|
||||
goog.object.extend(localContext, context);
|
||||
}
|
||||
goog.object.extend(localContext, this.dimensions_);
|
||||
var url = template;
|
||||
for (var key in localContext) {
|
||||
url = url.replace('{' + key + '}', localContext[key])
|
||||
.replace('%7B' + key + '%7D', localContext[key]);
|
||||
if (requestEncoding == ol.source.WMTSRequestEncoding.KVP) {
|
||||
url = goog.uri.utils.appendParamsFromMap(url, localContext);
|
||||
} else {
|
||||
url = url.replace(/\{(\w+?)\}/g, function(m, p) {
|
||||
return localContext[p];
|
||||
});
|
||||
}
|
||||
return url;
|
||||
}
|
||||
@@ -109,15 +121,7 @@ ol.source.WMTS = function(options) {
|
||||
}
|
||||
if (goog.isDef(urls)) {
|
||||
tileUrlFunction = ol.TileUrlFunction.createFromTileUrlFunctions(
|
||||
goog.array.map(urls, function(url) {
|
||||
if (goog.isDef(kvpParams)) {
|
||||
// TODO: we may want to create our own appendParams function
|
||||
// so that params order conforms to wmts spec guidance,
|
||||
// and so that we can avoid to escape special template params
|
||||
url = goog.uri.utils.appendParamsFromMap(url, kvpParams);
|
||||
}
|
||||
return createFromWMTSTemplate(url);
|
||||
}));
|
||||
goog.array.map(urls, createFromWMTSTemplate));
|
||||
}
|
||||
|
||||
var tmpExtent = ol.extent.createEmpty();
|
||||
@@ -173,6 +177,36 @@ ol.source.WMTS = function(options) {
|
||||
goog.inherits(ol.source.WMTS, ol.source.TileImage);
|
||||
|
||||
|
||||
/**
|
||||
* Get the dimensions, i.e. those passed to the constructor through the
|
||||
* "dimensions" option, and possibly updated using the updateDimensions
|
||||
* method.
|
||||
* @return {Object} Dimensions.
|
||||
*/
|
||||
ol.source.WMTS.prototype.getDimensions = function() {
|
||||
return this.dimensions_;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
ol.source.WMTS.prototype.getKeyZXY = function(z, x, y) {
|
||||
return goog.object.getValues(this.dimensions_).join('/') +
|
||||
goog.base(this, 'getKeyZXY', z, x, y);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Update the dimensions.
|
||||
* @param {Object} dimensions Dimensions.
|
||||
*/
|
||||
ol.source.WMTS.prototype.updateDimensions = function(dimensions) {
|
||||
goog.object.extend(this.dimensions_, dimensions);
|
||||
this.dispatchChangeEvent();
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {Object} wmtsCap An object representing the capabilities document.
|
||||
* @param {string} layer The layer identifier.
|
||||
|
||||
Reference in New Issue
Block a user