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
+66 -41
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 (
if (goog.isNull(tileCoord)) { /**
return undefined; * @param {ol.TileCoord} tileCoord Tile Coordinate.
} else { * @param {ol.Projection} projection Projection.
return template.replace('{z}', tileCoord.z) * @return {string|undefined} Tile URL.
.replace('{x}', tileCoord.x) */
.replace('{y}', tileCoord.y); function(tileCoord, projection) {
} if (goog.isNull(tileCoord)) {
}; return undefined;
} else {
return template.replace('{z}', '' + tileCoord.z)
.replace('{x}', '' + tileCoord.x)
.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 (
if (goog.isNull(tileCoord)) { /**
return undefined; * @param {ol.TileCoord} tileCoord Tile Coordinate.
} else { * @param {ol.Projection} projection Projection.
var index = goog.math.modulo(tileCoord.hash(), tileUrlFunctions.length); * @return {string|undefined} Tile URL.
return tileUrlFunctions[index].call(this, tileCoord, projection); */
} function(tileCoord, projection) {
}; if (goog.isNull(tileCoord)) {
return undefined;
} else {
var index =
goog.math.modulo(tileCoord.hash(), tileUrlFunctions.length);
return tileUrlFunctions[index].call(this, tileCoord, projection);
}
});
}; };
@@ -69,20 +82,26 @@ 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 (
if (goog.isNull(tileCoord)) { /**
return undefined; * @param {ol.TileCoord} tileCoord Tile Coordinate.
} else { * @param {ol.Projection} projection Projection.
var tileGrid = this.getTileGrid(); * @return {string|undefined} Tile URL.
if (goog.isNull(tileGrid)) { */
tileGrid = ol.tilegrid.getForProjection(projection); function(tileCoord, projection) {
} if (goog.isNull(tileCoord)) {
var size = tileGrid.getTileSize(tileCoord.z); return undefined;
var extent = tileGrid.getTileCoordExtent(tileCoord, tmpExtent); } else {
return paramsFunction.call(this, baseUrl, params, var tileGrid = this.getTileGrid();
extent, size, projection); if (goog.isNull(tileGrid)) {
} tileGrid = ol.tilegrid.getForProjection(projection);
}; }
var size = tileGrid.getTileSize(tileCoord.z);
var extent = tileGrid.getTileCoordExtent(tileCoord, tmpExtent);
return paramsFunction.call(this, baseUrl, params,
extent, size, projection);
}
});
}; };
@@ -105,16 +124,22 @@ 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 (
if (goog.isNull(tileCoord)) { /**
return undefined; * @param {ol.TileCoord} tileCoord Tile Coordinate.
} else { * @param {ol.Projection} projection Projection.
return tileUrlFunction.call( * @return {string|undefined} Tile URL.
this, */
transformFn.call(this, tileCoord, projection, tmpTileCoord), function(tileCoord, projection) {
projection); if (goog.isNull(tileCoord)) {
} return undefined;
}; } else {
return tileUrlFunction.call(
this,
transformFn.call(this, tileCoord, projection, tmpTileCoord),
projection);
}
});
}; };