From bff25f9ba4ed90bd3817fe12b5540aea7cf11a77 Mon Sep 17 00:00:00 2001 From: Andreas Hocevar Date: Thu, 10 Sep 2020 10:10:52 +0200 Subject: [PATCH] Bind tileUrlFunction before returning it from getTileUrlFunction --- src/ol/source/UrlTile.js | 6 ++++-- test/spec/ol/source/tilewms.test.js | 9 +++++++++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/ol/source/UrlTile.js b/src/ol/source/UrlTile.js index f4303fe0d0..f0d20eb3a4 100644 --- a/src/ol/source/UrlTile.js +++ b/src/ol/source/UrlTile.js @@ -68,7 +68,7 @@ class UrlTile extends TileSource { this.tileLoadFunction = options.tileLoadFunction; if (options.tileUrlFunction) { - this.tileUrlFunction = options.tileUrlFunction.bind(this); + this.tileUrlFunction = options.tileUrlFunction; } /** @@ -105,7 +105,9 @@ class UrlTile extends TileSource { * @api */ getTileUrlFunction() { - return this.tileUrlFunction; + return Object.getPrototypeOf(this).tileUrlFunction === this.tileUrlFunction + ? this.tileUrlFunction.bind(this) + : this.tileUrlFunction; } /** diff --git a/test/spec/ol/source/tilewms.test.js b/test/spec/ol/source/tilewms.test.js index 6df7258cb8..7bd16e92b2 100644 --- a/test/spec/ol/source/tilewms.test.js +++ b/test/spec/ol/source/tilewms.test.js @@ -159,6 +159,15 @@ describe('ol.source.TileWMS', function () { }); describe('#tileUrlFunction', function () { + it('can be used when obtained through #getTileUrlFunction', function () { + options.extent = [-80, -40, -50, -10]; + const source = new TileWMS(options); + const tileCoord = [3, 2, 2]; + expect(function () { + source.getTileUrlFunction()(tileCoord, 1, getProjection('EPSG:4326')); + }).to.not.throwException(); + }); + it('returns a tile if it is contained within layers extent', function () { options.extent = [-80, -40, -50, -10]; const source = new TileWMS(options);