Handle urls and templates in ol.source.UrlTile

This makes url templates available for ol.source.VectorTile.
This commit is contained in:
Andreas Hocevar
2015-10-01 19:19:37 +02:00
parent af69933c64
commit 4784b7f2e2
8 changed files with 131 additions and 178 deletions

View File

@@ -7,7 +7,6 @@ goog.require('goog.string');
goog.require('goog.uri.utils');
goog.require('ol');
goog.require('ol.TileCoord');
goog.require('ol.TileUrlFunction');
goog.require('ol.extent');
goog.require('ol.proj');
goog.require('ol.size');
@@ -45,20 +44,11 @@ ol.source.TileArcGISRest = function(opt_options) {
tileGrid: options.tileGrid,
tileLoadFunction: options.tileLoadFunction,
tileUrlFunction: goog.bind(this.tileUrlFunction_, this),
url: options.url,
urls: options.urls,
wrapX: options.wrapX !== undefined ? options.wrapX : true
});
var urls = options.urls;
if (urls === undefined && options.url !== undefined) {
urls = ol.TileUrlFunction.expandUrl(options.url);
}
/**
* @private
* @type {!Array.<string>}
*/
this.urls_ = urls || [];
/**
* @private
* @type {Object}
@@ -100,7 +90,7 @@ ol.source.TileArcGISRest.prototype.getRequestUrl_ =
function(tileCoord, tileSize, tileExtent,
pixelRatio, projection, params) {
var urls = this.urls_;
var urls = this.urls;
if (urls.length === 0) {
return undefined;
}
@@ -158,38 +148,6 @@ ol.source.TileArcGISRest.prototype.getTilePixelSize =
};
/**
* Return the URLs used for this ArcGIS source.
* @return {!Array.<string>} URLs.
* @api stable
*/
ol.source.TileArcGISRest.prototype.getUrls = function() {
return this.urls_;
};
/**
* Set the URL to use for requests.
* @param {string|undefined} url URL.
* @api stable
*/
ol.source.TileArcGISRest.prototype.setUrl = function(url) {
var urls = url !== undefined ? ol.TileUrlFunction.expandUrl(url) : null;
this.setUrls(urls);
};
/**
* Set the URLs to use for requests.
* @param {Array.<string>|undefined} urls URLs.
* @api stable
*/
ol.source.TileArcGISRest.prototype.setUrls = function(urls) {
this.urls_ = urls || [];
this.changed();
};
/**
* @param {ol.TileCoord} tileCoord Tile coordinate.
* @param {number} pixelRatio Pixel ratio.

View File

@@ -38,6 +38,8 @@ ol.source.TileImage = function(options) {
options.tileLoadFunction : ol.source.TileImage.defaultTileLoadFunction,
tilePixelRatio: options.tilePixelRatio,
tileUrlFunction: options.tileUrlFunction,
url: options.url,
urls: options.urls,
wrapX: options.wrapX
});

View File

@@ -11,7 +11,6 @@ goog.require('goog.string');
goog.require('goog.uri.utils');
goog.require('ol');
goog.require('ol.TileCoord');
goog.require('ol.TileUrlFunction');
goog.require('ol.extent');
goog.require('ol.proj');
goog.require('ol.size');
@@ -49,20 +48,11 @@ ol.source.TileWMS = function(opt_options) {
tileGrid: options.tileGrid,
tileLoadFunction: options.tileLoadFunction,
tileUrlFunction: goog.bind(this.tileUrlFunction_, this),
url: options.url,
urls: options.urls,
wrapX: options.wrapX !== undefined ? options.wrapX : true
});
var urls = options.urls;
if (urls === undefined && options.url !== undefined) {
urls = ol.TileUrlFunction.expandUrl(options.url);
}
/**
* @private
* @type {!Array.<string>}
*/
this.urls_ = urls || [];
/**
* @private
* @type {number}
@@ -221,7 +211,7 @@ ol.source.TileWMS.prototype.getRequestUrl_ =
function(tileCoord, tileSize, tileExtent,
pixelRatio, projection, params) {
var urls = this.urls_;
var urls = this.urls;
if (urls.length === 0) {
return undefined;
}
@@ -301,16 +291,6 @@ ol.source.TileWMS.prototype.getTilePixelSize =
};
/**
* Return the URLs used for this WMS source.
* @return {!Array.<string>} URLs.
* @api stable
*/
ol.source.TileWMS.prototype.getUrls = function() {
return this.urls_;
};
/**
* @private
*/
@@ -319,8 +299,8 @@ ol.source.TileWMS.prototype.resetCoordKeyPrefix_ = function() {
var res = [];
var j, jj;
for (j = 0, jj = this.urls_.length; j < jj; ++j) {
res[i++] = this.urls_[j];
for (j = 0, jj = this.urls.length; j < jj; ++j) {
res[i++] = this.urls[j];
}
var key;
@@ -332,29 +312,6 @@ ol.source.TileWMS.prototype.resetCoordKeyPrefix_ = function() {
};
/**
* Set the URL to use for requests.
* @param {string|undefined} url URL.
* @api stable
*/
ol.source.TileWMS.prototype.setUrl = function(url) {
var urls = url !== undefined ? ol.TileUrlFunction.expandUrl(url) : null;
this.setUrls(urls);
};
/**
* Set the URLs to use for requests.
* @param {Array.<string>|undefined} urls URLs.
* @api stable
*/
ol.source.TileWMS.prototype.setUrls = function(urls) {
this.urls_ = urls || [];
this.resetCoordKeyPrefix_();
this.changed();
};
/**
* @param {ol.TileCoord} tileCoord Tile coordinate.
* @param {number} pixelRatio Pixel ratio.

View File

@@ -5,6 +5,7 @@ goog.require('ol.TileLoadFunctionType');
goog.require('ol.TileState');
goog.require('ol.TileUrlFunction');
goog.require('ol.TileUrlFunctionType');
goog.require('ol.proj');
goog.require('ol.source.Tile');
goog.require('ol.source.TileEvent');
@@ -20,6 +21,8 @@ goog.require('ol.source.TileEvent');
* tileLoadFunction: ol.TileLoadFunctionType,
* tilePixelRatio: (number|undefined),
* tileUrlFunction: (ol.TileUrlFunctionType|undefined),
* url: (string|undefined),
* urls: (Array.<string>|undefined),
* wrapX: (boolean|undefined)}}
*/
ol.source.UrlTileOptions;
@@ -51,19 +54,38 @@ ol.source.UrlTile = function(options) {
wrapX: options.wrapX
});
/**
* @protected
* @type {ol.TileLoadFunctionType}
*/
this.tileLoadFunction = options.tileLoadFunction;
/**
* @protected
* @type {ol.TileUrlFunctionType}
*/
this.tileUrlFunction = goog.isDef(options.tileUrlFunction) ?
this.tileUrlFunction = options.tileUrlFunction ?
options.tileUrlFunction :
ol.TileUrlFunction.nullTileUrlFunction;
/**
* @protected
* @type {ol.TileLoadFunctionType}
* @type {!Array.<string>|null}
*/
this.tileLoadFunction = options.tileLoadFunction;
this.urls = null;
if (options.urls) {
if (options.tileUrlFunction) {
this.urls = options.urls;
} else {
this.setUrls(options.urls);
}
} else if (options.url) {
this.setUrl(options.url);
}
if (options.tileUrlFunction) {
this.setTileUrlFunction(options.tileUrlFunction);
}
};
goog.inherits(ol.source.UrlTile, ol.source.Tile);
@@ -89,6 +111,18 @@ ol.source.UrlTile.prototype.getTileUrlFunction = function() {
};
/**
* Return the URLs used for this XYZ source.
* When a tileUrlFunction is used instead of url or urls,
* null will be returned.
* @return {!Array.<string>|null} URLs.
* @api
*/
ol.source.UrlTile.prototype.getUrls = function() {
return this.urls;
};
/**
* Handle tile change events.
* @param {goog.events.Event} event Event.
@@ -140,6 +174,30 @@ ol.source.UrlTile.prototype.setTileUrlFunction = function(tileUrlFunction) {
};
/**
* Set the URL to use for requests.
* @param {string} url URL.
* @api stable
*/
ol.source.UrlTile.prototype.setUrl = function(url) {
this.setTileUrlFunction(ol.TileUrlFunction.createFromTemplates(
ol.TileUrlFunction.expandUrl(url), this.tileGrid));
this.urls = [url];
};
/**
* Set the URLs to use for requests.
* @param {Array.<string>} urls URLs.
* @api stable
*/
ol.source.UrlTile.prototype.setUrls = function(urls) {
this.setTileUrlFunction(ol.TileUrlFunction.createFromTemplates(
urls, this.tileGrid));
this.urls = urls;
};
/**
* @inheritDoc
*/

View File

@@ -42,6 +42,8 @@ ol.source.VectorTile = function(options) {
options.tileLoadFunction : ol.source.VectorTile.defaultTileLoadFunction,
tileUrlFunction: options.tileUrlFunction,
tilePixelRatio: options.tilePixelRatio,
url: options.url,
urls: options.urls,
wrapX: options.wrapX === undefined ? true : options.wrapX
});

View File

@@ -87,12 +87,6 @@ ol.source.WMTS = function(options) {
urls = ol.TileUrlFunction.expandUrl(options.url);
}
/**
* @private
* @type {!Array.<string>}
*/
this.urls_ = urls || [];
// FIXME: should we guess this requestEncoding from options.url(s)
// structure? that would mean KVP only if a template is not provided.
@@ -175,9 +169,9 @@ ol.source.WMTS = function(options) {
});
}
var tileUrlFunction = this.urls_.length > 0 ?
var tileUrlFunction = (urls && urls.length > 0) ?
ol.TileUrlFunction.createFromTileUrlFunctions(
this.urls_.map(createFromWMTSTemplate)) :
urls.map(createFromWMTSTemplate)) :
ol.TileUrlFunction.nullTileUrlFunction;
goog.base(this, {
@@ -191,6 +185,7 @@ ol.source.WMTS = function(options) {
tileLoadFunction: options.tileLoadFunction,
tilePixelRatio: options.tilePixelRatio,
tileUrlFunction: tileUrlFunction,
urls: urls,
wrapX: options.wrapX !== undefined ? options.wrapX : false
});
@@ -268,16 +263,6 @@ ol.source.WMTS.prototype.getStyle = function() {
};
/**
* Return the URLs used for this WMTS source.
* @return {!Array.<string>} URLs.
* @api
*/
ol.source.WMTS.prototype.getUrls = function() {
return this.urls_;
};
/**
* Return the version of the WMTS source.
* @return {string} Version.

View File

@@ -1,6 +1,5 @@
goog.provide('ol.source.XYZ');
goog.require('ol.TileUrlFunction');
goog.require('ol.source.TileImage');
@@ -38,12 +37,6 @@ ol.source.XYZ = function(options) {
tileSize: options.tileSize
});
/**
* @private
* @type {!Array.<string>|null}
*/
this.urls_ = null;
goog.base(this, {
attributions: options.attributions,
crossOrigin: options.crossOrigin,
@@ -53,52 +46,11 @@ ol.source.XYZ = function(options) {
tileGrid: tileGrid,
tileLoadFunction: options.tileLoadFunction,
tilePixelRatio: options.tilePixelRatio,
tileUrlFunction: ol.TileUrlFunction.nullTileUrlFunction,
tileUrlFunction: options.tileUrlFunction,
url: options.url,
urls: options.urls,
wrapX: options.wrapX !== undefined ? options.wrapX : true
});
if (options.tileUrlFunction !== undefined) {
this.setTileUrlFunction(options.tileUrlFunction);
} else if (options.urls !== undefined) {
this.setUrls(options.urls);
} else if (options.url !== undefined) {
this.setUrl(options.url);
}
};
goog.inherits(ol.source.XYZ, ol.source.TileImage);
/**
* Return the URLs used for this XYZ source.
* When a tileUrlFunction is used instead of url or urls,
* null will be returned.
* @return {!Array.<string>|null} URLs.
* @api
*/
ol.source.XYZ.prototype.getUrls = function() {
return this.urls_;
};
/**
* Set the URL to use for requests.
* @param {string} url URL.
* @api stable
*/
ol.source.XYZ.prototype.setUrl = function(url) {
this.setTileUrlFunction(ol.TileUrlFunction.createFromTemplates(
ol.TileUrlFunction.expandUrl(url), this.tileGrid));
this.urls_ = [url];
};
/**
* Set the URLs to use for requests.
* @param {Array.<string>} urls URLs.
*/
ol.source.XYZ.prototype.setUrls = function(urls) {
this.setTileUrlFunction(
ol.TileUrlFunction.createFromTemplates(urls, this.tileGrid));
this.urls_ = urls;
};