s/TileUrl/TileUrlFunction/

This commit is contained in:
Tom Payne
2012-07-08 12:21:35 +02:00
committed by Tom Payne
parent 58e9ba322e
commit d30c30f01d
3 changed files with 15 additions and 13 deletions

36
src/ol/tileurlfunction.js Normal file
View File

@@ -0,0 +1,36 @@
goog.provide('ol.TileUrlFunction');
goog.provide('ol.TileUrlFunctionType');
goog.require('goog.math');
goog.require('ol.TileCoord');
/**
* @typedef {function(ol.TileCoord): string}
*/
ol.TileUrlFunctionType;
/**
* @param {string} template Template.
* @return {ol.TileUrlFunctionType} Tile URL function.
*/
ol.TileUrlFunction.createFromTemplate = function(template) {
return function(tileCoord) {
return template.replace(/\{z\}/, tileCoord.z)
.replace(/\{x\}/, tileCoord.x)
.replace(/\{y\}/, tileCoord.y);
};
};
/**
* @param {Array.<ol.TileUrlFunctionType>} tileUrlFunctions Tile URL Functions.
* @return {ol.TileUrlFunctionType} Tile URL function.
*/
ol.TileUrlFunction.createFromTileUrlFunctions = function(tileUrlFunctions) {
return function(tileCoord) {
var index = goog.math.modulo(tileCoord.hash(), tileUrlFunctions.length);
return tileUrlFunctions[index](tileCoord);
};
};