Improve type checking in ol.TileUrlFunction

This commit is contained in:
Tom Payne
2013-04-30 21:35:28 +02:00
parent 0e69af847e
commit 0541053fa9
+37 -12
View File
@@ -18,15 +18,21 @@ ol.TileUrlFunctionType;
* @return {ol.TileUrlFunctionType} Tile URL function. * @return {ol.TileUrlFunctionType} Tile URL function.
*/ */
ol.TileUrlFunction.createFromTemplate = function(template) { ol.TileUrlFunction.createFromTemplate = function(template) {
return function(tileCoord) { return (
/**
* @param {ol.TileCoord} tileCoord Tile Coordinate.
* @param {ol.Projection} projection Projection.
* @return {string|undefined} Tile URL.
*/
function(tileCoord, projection) {
if (goog.isNull(tileCoord)) { if (goog.isNull(tileCoord)) {
return undefined; return undefined;
} else { } else {
return template.replace('{z}', tileCoord.z) return template.replace('{z}', '' + tileCoord.z)
.replace('{x}', tileCoord.x) .replace('{x}', '' + tileCoord.x)
.replace('{y}', tileCoord.y); .replace('{y}', '' + tileCoord.y);
} }
}; });
}; };
@@ -48,14 +54,21 @@ ol.TileUrlFunction.createFromTileUrlFunctions = function(tileUrlFunctions) {
if (tileUrlFunctions.length === 1) { if (tileUrlFunctions.length === 1) {
return tileUrlFunctions[0]; return tileUrlFunctions[0];
} }
return function(tileCoord, projection) { return (
/**
* @param {ol.TileCoord} tileCoord Tile Coordinate.
* @param {ol.Projection} projection Projection.
* @return {string|undefined} Tile URL.
*/
function(tileCoord, projection) {
if (goog.isNull(tileCoord)) { if (goog.isNull(tileCoord)) {
return undefined; return undefined;
} else { } else {
var index = goog.math.modulo(tileCoord.hash(), tileUrlFunctions.length); var index =
goog.math.modulo(tileCoord.hash(), tileUrlFunctions.length);
return tileUrlFunctions[index].call(this, tileCoord, projection); return tileUrlFunctions[index].call(this, tileCoord, projection);
} }
}; });
}; };
@@ -69,7 +82,13 @@ ol.TileUrlFunction.createFromTileUrlFunctions = function(tileUrlFunctions) {
ol.TileUrlFunction.createFromParamsFunction = ol.TileUrlFunction.createFromParamsFunction =
function(baseUrl, params, paramsFunction) { function(baseUrl, params, paramsFunction) {
var tmpExtent = ol.extent.createEmptyExtent(); var tmpExtent = ol.extent.createEmptyExtent();
return function(tileCoord, projection) { return (
/**
* @param {ol.TileCoord} tileCoord Tile Coordinate.
* @param {ol.Projection} projection Projection.
* @return {string|undefined} Tile URL.
*/
function(tileCoord, projection) {
if (goog.isNull(tileCoord)) { if (goog.isNull(tileCoord)) {
return undefined; return undefined;
} else { } else {
@@ -82,7 +101,7 @@ ol.TileUrlFunction.createFromParamsFunction =
return paramsFunction.call(this, baseUrl, params, return paramsFunction.call(this, baseUrl, params,
extent, size, projection); extent, size, projection);
} }
}; });
}; };
@@ -105,7 +124,13 @@ ol.TileUrlFunction.nullTileUrlFunction = function(tileCoord, projection) {
ol.TileUrlFunction.withTileCoordTransform = ol.TileUrlFunction.withTileCoordTransform =
function(transformFn, tileUrlFunction) { function(transformFn, tileUrlFunction) {
var tmpTileCoord = new ol.TileCoord(0, 0, 0); var tmpTileCoord = new ol.TileCoord(0, 0, 0);
return function(tileCoord, projection) { return (
/**
* @param {ol.TileCoord} tileCoord Tile Coordinate.
* @param {ol.Projection} projection Projection.
* @return {string|undefined} Tile URL.
*/
function(tileCoord, projection) {
if (goog.isNull(tileCoord)) { if (goog.isNull(tileCoord)) {
return undefined; return undefined;
} else { } else {
@@ -114,7 +139,7 @@ ol.TileUrlFunction.withTileCoordTransform =
transformFn.call(this, tileCoord, projection, tmpTileCoord), transformFn.call(this, tileCoord, projection, tmpTileCoord),
projection); projection);
} }
}; });
}; };