Merge pull request #11548 from ahocevar/bind-tileurlfunction
Bind tileUrlFunction before returning it from getTileUrlFunction
This commit is contained in:
@@ -68,7 +68,7 @@ class UrlTile extends TileSource {
|
|||||||
this.tileLoadFunction = options.tileLoadFunction;
|
this.tileLoadFunction = options.tileLoadFunction;
|
||||||
|
|
||||||
if (options.tileUrlFunction) {
|
if (options.tileUrlFunction) {
|
||||||
this.tileUrlFunction = options.tileUrlFunction.bind(this);
|
this.tileUrlFunction = options.tileUrlFunction;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -105,7 +105,9 @@ class UrlTile extends TileSource {
|
|||||||
* @api
|
* @api
|
||||||
*/
|
*/
|
||||||
getTileUrlFunction() {
|
getTileUrlFunction() {
|
||||||
return this.tileUrlFunction;
|
return Object.getPrototypeOf(this).tileUrlFunction === this.tileUrlFunction
|
||||||
|
? this.tileUrlFunction.bind(this)
|
||||||
|
: this.tileUrlFunction;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -159,6 +159,15 @@ describe('ol.source.TileWMS', function () {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe('#tileUrlFunction', 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 () {
|
it('returns a tile if it is contained within layers extent', function () {
|
||||||
options.extent = [-80, -40, -50, -10];
|
options.extent = [-80, -40, -50, -10];
|
||||||
const source = new TileWMS(options);
|
const source = new TileWMS(options);
|
||||||
|
|||||||
Reference in New Issue
Block a user