From d2cc04d770d7bc385080c95e712aae2d68d9921c Mon Sep 17 00:00:00 2001 From: Guillaume Beraudo Date: Wed, 20 Jan 2016 16:37:38 +0100 Subject: [PATCH] Bind tileUrlFunction to the source In order to have the function returned by ol.source.UrlTile#getTileUrlFunction() to return a url even when executed outside the context of the source, then it should be bound to the source. --- src/ol/source/urltilesource.js | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/ol/source/urltilesource.js b/src/ol/source/urltilesource.js index c87c25be5e..febd9b10fa 100644 --- a/src/ol/source/urltilesource.js +++ b/src/ol/source/urltilesource.js @@ -63,8 +63,9 @@ ol.source.UrlTile = function(options) { * @protected * @type {ol.TileUrlFunctionType} */ - this.tileUrlFunction = - this.fixedTileUrlFunction || ol.TileUrlFunction.nullTileUrlFunction; + this.tileUrlFunction = this.fixedTileUrlFunction ? + this.fixedTileUrlFunction.bind(this) : + ol.TileUrlFunction.nullTileUrlFunction; /** * @protected @@ -184,7 +185,8 @@ ol.source.UrlTile.prototype.setTileUrlFunction = function(tileUrlFunction) { ol.source.UrlTile.prototype.setUrl = function(url) { this.urls = [url]; var urls = ol.TileUrlFunction.expandUrl(url); - this.setTileUrlFunction(this.fixedTileUrlFunction || + this.setTileUrlFunction(this.fixedTileUrlFunction ? + this.fixedTileUrlFunction.bind(this) : ol.TileUrlFunction.createFromTemplates(urls, this.tileGrid)); }; @@ -196,7 +198,8 @@ ol.source.UrlTile.prototype.setUrl = function(url) { */ ol.source.UrlTile.prototype.setUrls = function(urls) { this.urls = urls; - this.setTileUrlFunction(this.fixedTileUrlFunction || + this.setTileUrlFunction(this.fixedTileUrlFunction ? + this.fixedTileUrlFunction.bind(this) : ol.TileUrlFunction.createFromTemplates(urls, this.tileGrid)); };