diff --git a/src/ol/source/wmtssource.js b/src/ol/source/wmtssource.js index 13ee9b4a0a..53eb1f3bcb 100644 --- a/src/ol/source/wmtssource.js +++ b/src/ol/source/wmtssource.js @@ -96,10 +96,17 @@ ol.source.WMTS = function(options) { // 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) ? + + /** + * @private + * @type {ol.source.WMTSRequestEncoding} + */ + this.requestEncoding_ = goog.isDef(options.requestEncoding) ? /** @type {ol.source.WMTSRequestEncoding} */ (options.requestEncoding) : ol.source.WMTSRequestEncoding.KVP; + var requestEncoding = this.requestEncoding_; + // FIXME: should we create a default tileGrid? // we could issue a getCapabilities xhr to retrieve missing configuration var tileGrid = options.tileGrid; @@ -268,6 +275,16 @@ ol.source.WMTS.prototype.getMatrixSet = function() { }; +/** + * Return the request encoding, either "KVP" or "REST". + * @return {ol.source.WMTSRequestEncoding} Request encoding. + * @api + */ +ol.source.WMTS.prototype.getRequestEncoding = function() { + return this.requestEncoding_; +}; + + /** * Return the style of the WMTS source. * @return {string} Style. diff --git a/test/spec/ol/source/wmtssource.test.js b/test/spec/ol/source/wmtssource.test.js index ca9ffb49f9..2943040969 100644 --- a/test/spec/ol/source/wmtssource.test.js +++ b/test/spec/ol/source/wmtssource.test.js @@ -209,6 +209,32 @@ describe('ol.source.WMTS', function() { }); }); + + describe('#getRequestEncoding', function() { + + var source; + + beforeEach(function() { + source = new ol.source.WMTS({ + layer: 'layer', + style: 'default', + matrixSet: 'foo', + requestEncoding: 'REST', + tileGrid: new ol.tilegrid.WMTS({ + origin: [0, 0], + resolutions: [], + matrixIds: [] + }) + }); + }); + + it('returns the request encoding', function() { + var requestEncoding = source.getRequestEncoding(); + expect(requestEncoding).to.be.eql('REST'); + }); + + }); + }); goog.require('ol.format.WMTSCapabilities');