Merge pull request #4673 from ahocevar/fixed-tileurlfunction
Respect fixed tile url functions when setting url(s)
This commit is contained in:
@@ -42,7 +42,6 @@ ol.source.TileArcGISRest = function(opt_options) {
|
|||||||
reprojectionErrorThreshold: options.reprojectionErrorThreshold,
|
reprojectionErrorThreshold: options.reprojectionErrorThreshold,
|
||||||
tileGrid: options.tileGrid,
|
tileGrid: options.tileGrid,
|
||||||
tileLoadFunction: options.tileLoadFunction,
|
tileLoadFunction: options.tileLoadFunction,
|
||||||
tileUrlFunction: this.tileUrlFunction_.bind(this),
|
|
||||||
url: options.url,
|
url: options.url,
|
||||||
urls: options.urls,
|
urls: options.urls,
|
||||||
wrapX: options.wrapX !== undefined ? options.wrapX : true
|
wrapX: options.wrapX !== undefined ? options.wrapX : true
|
||||||
@@ -138,13 +137,9 @@ ol.source.TileArcGISRest.prototype.getTilePixelRatio = function(pixelRatio) {
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {ol.TileCoord} tileCoord Tile coordinate.
|
* @inheritDoc
|
||||||
* @param {number} pixelRatio Pixel ratio.
|
|
||||||
* @param {ol.proj.Projection} projection Projection.
|
|
||||||
* @return {string|undefined} Tile URL.
|
|
||||||
* @private
|
|
||||||
*/
|
*/
|
||||||
ol.source.TileArcGISRest.prototype.tileUrlFunction_ = function(tileCoord, pixelRatio, projection) {
|
ol.source.TileArcGISRest.prototype.fixedTileUrlFunction = function(tileCoord, pixelRatio, projection) {
|
||||||
|
|
||||||
var tileGrid = this.getTileGrid();
|
var tileGrid = this.getTileGrid();
|
||||||
if (!tileGrid) {
|
if (!tileGrid) {
|
||||||
|
|||||||
@@ -46,7 +46,6 @@ ol.source.TileWMS = function(opt_options) {
|
|||||||
reprojectionErrorThreshold: options.reprojectionErrorThreshold,
|
reprojectionErrorThreshold: options.reprojectionErrorThreshold,
|
||||||
tileGrid: options.tileGrid,
|
tileGrid: options.tileGrid,
|
||||||
tileLoadFunction: options.tileLoadFunction,
|
tileLoadFunction: options.tileLoadFunction,
|
||||||
tileUrlFunction: this.tileUrlFunction_.bind(this),
|
|
||||||
url: options.url,
|
url: options.url,
|
||||||
urls: options.urls,
|
urls: options.urls,
|
||||||
wrapX: options.wrapX !== undefined ? options.wrapX : true
|
wrapX: options.wrapX !== undefined ? options.wrapX : true
|
||||||
@@ -301,13 +300,9 @@ ol.source.TileWMS.prototype.resetCoordKeyPrefix_ = function() {
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {ol.TileCoord} tileCoord Tile coordinate.
|
* @inheritDoc
|
||||||
* @param {number} pixelRatio Pixel ratio.
|
|
||||||
* @param {ol.proj.Projection} projection Projection.
|
|
||||||
* @return {string|undefined} Tile URL.
|
|
||||||
* @private
|
|
||||||
*/
|
*/
|
||||||
ol.source.TileWMS.prototype.tileUrlFunction_ = function(tileCoord, pixelRatio, projection) {
|
ol.source.TileWMS.prototype.fixedTileUrlFunction = function(tileCoord, pixelRatio, projection) {
|
||||||
|
|
||||||
var tileGrid = this.getTileGrid();
|
var tileGrid = this.getTileGrid();
|
||||||
if (!tileGrid) {
|
if (!tileGrid) {
|
||||||
|
|||||||
@@ -63,9 +63,8 @@ ol.source.UrlTile = function(options) {
|
|||||||
* @protected
|
* @protected
|
||||||
* @type {ol.TileUrlFunctionType}
|
* @type {ol.TileUrlFunctionType}
|
||||||
*/
|
*/
|
||||||
this.tileUrlFunction = options.tileUrlFunction ?
|
this.tileUrlFunction =
|
||||||
options.tileUrlFunction :
|
this.fixedTileUrlFunction || ol.TileUrlFunction.nullTileUrlFunction;
|
||||||
ol.TileUrlFunction.nullTileUrlFunction;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @protected
|
* @protected
|
||||||
@@ -74,11 +73,7 @@ ol.source.UrlTile = function(options) {
|
|||||||
this.urls = null;
|
this.urls = null;
|
||||||
|
|
||||||
if (options.urls) {
|
if (options.urls) {
|
||||||
if (options.tileUrlFunction) {
|
this.setUrls(options.urls);
|
||||||
this.urls = options.urls;
|
|
||||||
} else {
|
|
||||||
this.setUrls(options.urls);
|
|
||||||
}
|
|
||||||
} else if (options.url) {
|
} else if (options.url) {
|
||||||
this.setUrl(options.url);
|
this.setUrl(options.url);
|
||||||
}
|
}
|
||||||
@@ -90,6 +85,12 @@ ol.source.UrlTile = function(options) {
|
|||||||
goog.inherits(ol.source.UrlTile, ol.source.Tile);
|
goog.inherits(ol.source.UrlTile, ol.source.Tile);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @type {ol.TileUrlFunctionType|undefined}
|
||||||
|
* @protected
|
||||||
|
*/
|
||||||
|
ol.source.UrlTile.prototype.fixedTileUrlFunction;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return the tile load function of the source.
|
* Return the tile load function of the source.
|
||||||
* @return {ol.TileLoadFunctionType} TileLoadFunction
|
* @return {ol.TileLoadFunctionType} TileLoadFunction
|
||||||
@@ -181,9 +182,10 @@ ol.source.UrlTile.prototype.setTileUrlFunction = function(tileUrlFunction) {
|
|||||||
* @api stable
|
* @api stable
|
||||||
*/
|
*/
|
||||||
ol.source.UrlTile.prototype.setUrl = function(url) {
|
ol.source.UrlTile.prototype.setUrl = function(url) {
|
||||||
this.setTileUrlFunction(ol.TileUrlFunction.createFromTemplates(
|
|
||||||
ol.TileUrlFunction.expandUrl(url), this.tileGrid));
|
|
||||||
this.urls = [url];
|
this.urls = [url];
|
||||||
|
var urls = ol.TileUrlFunction.expandUrl(url);
|
||||||
|
this.setTileUrlFunction(this.fixedTileUrlFunction ||
|
||||||
|
ol.TileUrlFunction.createFromTemplates(urls, this.tileGrid));
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@@ -193,9 +195,9 @@ ol.source.UrlTile.prototype.setUrl = function(url) {
|
|||||||
* @api stable
|
* @api stable
|
||||||
*/
|
*/
|
||||||
ol.source.UrlTile.prototype.setUrls = function(urls) {
|
ol.source.UrlTile.prototype.setUrls = function(urls) {
|
||||||
this.setTileUrlFunction(ol.TileUrlFunction.createFromTemplates(
|
|
||||||
urls, this.tileGrid));
|
|
||||||
this.urls = urls;
|
this.urls = urls;
|
||||||
|
this.setTileUrlFunction(this.fixedTileUrlFunction ||
|
||||||
|
ol.TileUrlFunction.createFromTemplates(urls, this.tileGrid));
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -253,6 +253,9 @@ describe('ol.source.TileArcGISRest', function() {
|
|||||||
var urls = source.getUrls();
|
var urls = source.getUrls();
|
||||||
|
|
||||||
expect(urls).to.eql(['http://test3.com/MapServer']);
|
expect(urls).to.eql(['http://test3.com/MapServer']);
|
||||||
|
|
||||||
|
var tileUrl = source.tileUrlFunction([0, 0, 0], 1, ol.proj.get('EPSG:4326'));
|
||||||
|
expect(tileUrl.indexOf(urls[0])).to.be(0);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -258,6 +258,14 @@ describe('ol.source.TileWMS', function() {
|
|||||||
expect(uri.getFragment()).to.be.empty();
|
expect(uri.getFragment()).to.be.empty();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('#setUrl()', function() {
|
||||||
|
var source = new ol.source.TileWMS(options);
|
||||||
|
var url = 'http://foo/';
|
||||||
|
source.setUrl(url);
|
||||||
|
var tileUrl = source.tileUrlFunction([0, 0, 0], 1, ol.proj.get('EPSG:4326'));
|
||||||
|
expect(tileUrl.indexOf(url)).to.be(0);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user