Add getDimensions/updateDimensions to WMTS
This commit is contained in:
@@ -1,2 +1,4 @@
|
|||||||
@exportClass ol.source.WMTS ol.source.WMTSOptions
|
@exportClass ol.source.WMTS ol.source.WMTSOptions
|
||||||
|
@exportProperty ol.source.WMTS.prototype.getDimensions
|
||||||
|
@exportProperty ol.source.WMTS.prototype.updateDimensions
|
||||||
@exportSymbol ol.source.WMTS.optionsFromCapabilities
|
@exportSymbol ol.source.WMTS.optionsFromCapabilities
|
||||||
|
|||||||
+59
-25
@@ -36,7 +36,12 @@ ol.source.WMTS = function(options) {
|
|||||||
|
|
||||||
var version = goog.isDef(options.version) ? options.version : '1.0.0';
|
var version = goog.isDef(options.version) ? options.version : '1.0.0';
|
||||||
var format = goog.isDef(options.format) ? options.format : 'image/jpeg';
|
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)
|
// FIXME: should we guess this requestEncoding from options.url(s)
|
||||||
// structure? that would mean KVP only if a template is not provided.
|
// structure? that would mean KVP only if a template is not provided.
|
||||||
@@ -53,19 +58,14 @@ ol.source.WMTS = function(options) {
|
|||||||
'Style': options.style,
|
'Style': options.style,
|
||||||
'TileMatrixSet': options.matrixSet
|
'TileMatrixSet': options.matrixSet
|
||||||
};
|
};
|
||||||
goog.object.extend(context, dimensions);
|
|
||||||
var kvpParams;
|
|
||||||
if (requestEncoding == ol.source.WMTSRequestEncoding.KVP) {
|
if (requestEncoding == ol.source.WMTSRequestEncoding.KVP) {
|
||||||
kvpParams = {
|
goog.object.extend(context, {
|
||||||
'Service': 'WMTS',
|
'Service': 'WMTS',
|
||||||
'Request': 'GetTile',
|
'Request': 'GetTile',
|
||||||
'Version': version,
|
'Version': version,
|
||||||
'Format': format,
|
'Format': format
|
||||||
'TileMatrix': '{TileMatrix}',
|
});
|
||||||
'TileRow': '{TileRow}',
|
|
||||||
'TileCol': '{TileCol}'
|
|
||||||
};
|
|
||||||
goog.object.extend(kvpParams, context);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -73,6 +73,17 @@ ol.source.WMTS = function(options) {
|
|||||||
* @return {ol.TileUrlFunctionType} Tile URL function.
|
* @return {ol.TileUrlFunctionType} Tile URL function.
|
||||||
*/
|
*/
|
||||||
function createFromWMTSTemplate(template) {
|
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 (
|
return (
|
||||||
/**
|
/**
|
||||||
* @this {ol.source.WMTS}
|
* @this {ol.source.WMTS}
|
||||||
@@ -89,13 +100,14 @@ ol.source.WMTS = function(options) {
|
|||||||
'TileCol': tileCoord.x,
|
'TileCol': tileCoord.x,
|
||||||
'TileRow': tileCoord.y
|
'TileRow': tileCoord.y
|
||||||
};
|
};
|
||||||
if (requestEncoding != ol.source.WMTSRequestEncoding.KVP) {
|
goog.object.extend(localContext, this.dimensions_);
|
||||||
goog.object.extend(localContext, context);
|
|
||||||
}
|
|
||||||
var url = template;
|
var url = template;
|
||||||
for (var key in localContext) {
|
if (requestEncoding == ol.source.WMTSRequestEncoding.KVP) {
|
||||||
url = url.replace('{' + key + '}', localContext[key])
|
url = goog.uri.utils.appendParamsFromMap(url, localContext);
|
||||||
.replace('%7B' + key + '%7D', localContext[key]);
|
} else {
|
||||||
|
url = url.replace(/\{(\w+?)\}/g, function(m, p) {
|
||||||
|
return localContext[p];
|
||||||
|
});
|
||||||
}
|
}
|
||||||
return url;
|
return url;
|
||||||
}
|
}
|
||||||
@@ -109,15 +121,7 @@ ol.source.WMTS = function(options) {
|
|||||||
}
|
}
|
||||||
if (goog.isDef(urls)) {
|
if (goog.isDef(urls)) {
|
||||||
tileUrlFunction = ol.TileUrlFunction.createFromTileUrlFunctions(
|
tileUrlFunction = ol.TileUrlFunction.createFromTileUrlFunctions(
|
||||||
goog.array.map(urls, function(url) {
|
goog.array.map(urls, createFromWMTSTemplate));
|
||||||
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);
|
|
||||||
}));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var tmpExtent = ol.extent.createEmpty();
|
var tmpExtent = ol.extent.createEmpty();
|
||||||
@@ -173,6 +177,36 @@ ol.source.WMTS = function(options) {
|
|||||||
goog.inherits(ol.source.WMTS, ol.source.TileImage);
|
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 {Object} wmtsCap An object representing the capabilities document.
|
||||||
* @param {string} layer The layer identifier.
|
* @param {string} layer The layer identifier.
|
||||||
|
|||||||
Reference in New Issue
Block a user