Add ol.source.XYZ#setUrl and friends
This commit is contained in:
@@ -18,33 +18,12 @@ ol.source.XYZ = function(options) {
|
||||
|
||||
var projection = options.projection || ol.proj.get('EPSG:3857');
|
||||
|
||||
/**
|
||||
* @type {ol.TileUrlFunctionType}
|
||||
*/
|
||||
var tileUrlFunction = ol.TileUrlFunction.nullTileUrlFunction;
|
||||
// FIXME use goog.nullFunction ?
|
||||
if (goog.isDef(options.tileUrlFunction)) {
|
||||
tileUrlFunction = options.tileUrlFunction;
|
||||
} else if (goog.isDef(options.urls)) {
|
||||
tileUrlFunction = ol.TileUrlFunction.createFromTemplates(options.urls);
|
||||
} else if (goog.isDef(options.url)) {
|
||||
tileUrlFunction = ol.TileUrlFunction.createFromTemplates(
|
||||
ol.TileUrlFunction.expandUrl(options.url));
|
||||
}
|
||||
|
||||
var maxZoom = goog.isDef(options.maxZoom) ? options.maxZoom : 18;
|
||||
|
||||
var tileGrid = new ol.tilegrid.XYZ({
|
||||
maxZoom: maxZoom
|
||||
});
|
||||
|
||||
var tileCoordTransform = tileGrid.createTileCoordTransform({
|
||||
extent: options.extent
|
||||
});
|
||||
|
||||
tileUrlFunction = ol.TileUrlFunction.withTileCoordTransform(
|
||||
tileCoordTransform, tileUrlFunction);
|
||||
|
||||
goog.base(this, {
|
||||
attributions: options.attributions,
|
||||
crossOrigin: options.crossOrigin,
|
||||
@@ -52,8 +31,51 @@ ol.source.XYZ = function(options) {
|
||||
logo: options.logo,
|
||||
projection: projection,
|
||||
tileGrid: tileGrid,
|
||||
tileUrlFunction: tileUrlFunction
|
||||
tileUrlFunction: ol.TileUrlFunction.nullTileUrlFunction
|
||||
});
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {ol.TileCoordTransformType}
|
||||
*/
|
||||
this.tileCoordTransform_ = tileGrid.createTileCoordTransform({
|
||||
extent: options.extent
|
||||
});
|
||||
|
||||
if (goog.isDef(options.tileUrlFunction)) {
|
||||
this.setTileUrlFunction(options.tileUrlFunction);
|
||||
} else if (goog.isDef(options.urls)) {
|
||||
this.setUrls(options.urls);
|
||||
} else if (goog.isDef(options.url)) {
|
||||
this.setUrl(options.url);
|
||||
}
|
||||
|
||||
};
|
||||
goog.inherits(ol.source.XYZ, ol.source.TileImage);
|
||||
|
||||
|
||||
/**
|
||||
* @param {ol.TileUrlFunctionType} tileUrlFunction Tile URL function.
|
||||
*/
|
||||
ol.source.XYZ.prototype.setTileUrlFunction = function(tileUrlFunction) {
|
||||
goog.base(this, 'setTileUrlFunction',
|
||||
ol.TileUrlFunction.withTileCoordTransform(
|
||||
this.tileCoordTransform_, tileUrlFunction));
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {string} url URL.
|
||||
*/
|
||||
ol.source.XYZ.prototype.setUrl = function(url) {
|
||||
this.setTileUrlFunction(ol.TileUrlFunction.createFromTemplates(
|
||||
ol.TileUrlFunction.expandUrl(url)));
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {Array.<string>} urls URLs.
|
||||
*/
|
||||
ol.source.XYZ.prototype.setUrls = function(urls) {
|
||||
this.setTileUrlFunction(ol.TileUrlFunction.createFromTemplates(urls));
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user