Add ol.source.WMTS#getUrls
This commit is contained in:
@@ -83,6 +83,17 @@ ol.source.WMTS = function(options) {
|
|||||||
*/
|
*/
|
||||||
this.style_ = options.style;
|
this.style_ = options.style;
|
||||||
|
|
||||||
|
var urls = options.urls;
|
||||||
|
if (!goog.isDef(urls) && goog.isDef(options.url)) {
|
||||||
|
urls = ol.TileUrlFunction.expandUrl(options.url);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @private
|
||||||
|
* @type {!Array.<string>}
|
||||||
|
*/
|
||||||
|
this.urls_ = goog.isDefAndNotNull(urls) ? urls : [];
|
||||||
|
|
||||||
// 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.
|
||||||
var requestEncoding = goog.isDef(options.requestEncoding) ?
|
var requestEncoding = goog.isDef(options.requestEncoding) ?
|
||||||
@@ -158,15 +169,10 @@ ol.source.WMTS = function(options) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
var tileUrlFunction = ol.TileUrlFunction.nullTileUrlFunction;
|
var tileUrlFunction = this.urls_.length > 0 ?
|
||||||
var urls = options.urls;
|
ol.TileUrlFunction.createFromTileUrlFunctions(
|
||||||
if (!goog.isDef(urls) && goog.isDef(options.url)) {
|
goog.array.map(this.urls_, createFromWMTSTemplate)) :
|
||||||
urls = ol.TileUrlFunction.expandUrl(options.url);
|
ol.TileUrlFunction.nullTileUrlFunction;
|
||||||
}
|
|
||||||
if (goog.isDef(urls)) {
|
|
||||||
tileUrlFunction = ol.TileUrlFunction.createFromTileUrlFunctions(
|
|
||||||
goog.array.map(urls, createFromWMTSTemplate));
|
|
||||||
}
|
|
||||||
|
|
||||||
var tmpExtent = ol.extent.createEmpty();
|
var tmpExtent = ol.extent.createEmpty();
|
||||||
tileUrlFunction = ol.TileUrlFunction.withTileCoordTransform(
|
tileUrlFunction = ol.TileUrlFunction.withTileCoordTransform(
|
||||||
@@ -272,6 +278,16 @@ ol.source.WMTS.prototype.getStyle = function() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the URLs used for this WMTS source.
|
||||||
|
* @return {!Array.<string>} URLs.
|
||||||
|
* @api
|
||||||
|
*/
|
||||||
|
ol.source.WMTS.prototype.getUrls = function() {
|
||||||
|
return this.urls_;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return the version of the WMTS source.
|
* Return the version of the WMTS source.
|
||||||
* @return {string} Version.
|
* @return {string} Version.
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ goog.provide('ol.TileUrlFunction');
|
|||||||
goog.provide('ol.TileUrlFunctionType');
|
goog.provide('ol.TileUrlFunctionType');
|
||||||
|
|
||||||
goog.require('goog.array');
|
goog.require('goog.array');
|
||||||
|
goog.require('goog.asserts');
|
||||||
goog.require('goog.math');
|
goog.require('goog.math');
|
||||||
goog.require('ol.TileCoord');
|
goog.require('ol.TileCoord');
|
||||||
goog.require('ol.tilecoord');
|
goog.require('ol.tilecoord');
|
||||||
@@ -74,6 +75,8 @@ ol.TileUrlFunction.createFromTemplates = function(templates) {
|
|||||||
* @return {ol.TileUrlFunctionType} Tile URL function.
|
* @return {ol.TileUrlFunctionType} Tile URL function.
|
||||||
*/
|
*/
|
||||||
ol.TileUrlFunction.createFromTileUrlFunctions = function(tileUrlFunctions) {
|
ol.TileUrlFunction.createFromTileUrlFunctions = function(tileUrlFunctions) {
|
||||||
|
goog.asserts.assert(tileUrlFunctions.length > 0,
|
||||||
|
'Length of tile url functions should be greater than 0');
|
||||||
if (tileUrlFunctions.length === 1) {
|
if (tileUrlFunctions.length === 1) {
|
||||||
return tileUrlFunctions[0];
|
return tileUrlFunctions[0];
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -162,6 +162,53 @@ describe('ol.source.WMTS', function() {
|
|||||||
'Demographics/USA_Population_Density/MapServer/WMTS?');
|
'Demographics/USA_Population_Density/MapServer/WMTS?');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('#getUrls', function() {
|
||||||
|
|
||||||
|
var sourceOptions;
|
||||||
|
var source;
|
||||||
|
|
||||||
|
beforeEach(function() {
|
||||||
|
sourceOptions = {
|
||||||
|
layer: 'layer',
|
||||||
|
style: 'default',
|
||||||
|
matrixSet: 'foo',
|
||||||
|
requestEncoding: 'REST',
|
||||||
|
tileGrid: new ol.tilegrid.WMTS({
|
||||||
|
origin: [0, 0],
|
||||||
|
resolutions: [],
|
||||||
|
matrixIds: []
|
||||||
|
})
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('using a "url" option', function() {
|
||||||
|
beforeEach(function() {
|
||||||
|
sourceOptions.url = 'some_wmts_url';
|
||||||
|
source = new ol.source.WMTS(sourceOptions);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('returns the WMTS URLs', function() {
|
||||||
|
var urls = source.getUrls();
|
||||||
|
expect(urls).to.be.eql(['some_wmts_url']);
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('using a "urls" option', function() {
|
||||||
|
beforeEach(function() {
|
||||||
|
sourceOptions.urls = ['some_wmts_url1', 'some_wmts_url2'];
|
||||||
|
source = new ol.source.WMTS(sourceOptions);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('returns the WMTS URLs', function() {
|
||||||
|
var urls = source.getUrls();
|
||||||
|
expect(urls).to.be.eql(['some_wmts_url1', 'some_wmts_url2']);
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
goog.require('ol.format.WMTSCapabilities');
|
goog.require('ol.format.WMTSCapabilities');
|
||||||
|
|||||||
Reference in New Issue
Block a user