Allow out-of-range signalling with undefined
This commit is contained in:
@@ -6,7 +6,7 @@ goog.require('ol.TileCoord');
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @typedef {function(ol.TileCoord): string}
|
* @typedef {function(ol.TileCoord): string|undefined}
|
||||||
*/
|
*/
|
||||||
ol.TileUrlFunctionType;
|
ol.TileUrlFunctionType;
|
||||||
|
|
||||||
@@ -17,9 +17,13 @@ ol.TileUrlFunctionType;
|
|||||||
*/
|
*/
|
||||||
ol.TileUrlFunction.createFromTemplate = function(template) {
|
ol.TileUrlFunction.createFromTemplate = function(template) {
|
||||||
return function(tileCoord) {
|
return function(tileCoord) {
|
||||||
return template.replace(/\{z\}/, tileCoord.z)
|
if (goog.isNull(tileCoord)) {
|
||||||
.replace(/\{x\}/, tileCoord.x)
|
return undefined;
|
||||||
.replace(/\{y\}/, tileCoord.y);
|
} else {
|
||||||
|
return template.replace(/\{z\}/, tileCoord.z)
|
||||||
|
.replace(/\{x\}/, tileCoord.x)
|
||||||
|
.replace(/\{y\}/, tileCoord.y);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -30,8 +34,12 @@ ol.TileUrlFunction.createFromTemplate = function(template) {
|
|||||||
*/
|
*/
|
||||||
ol.TileUrlFunction.createFromTileUrlFunctions = function(tileUrlFunctions) {
|
ol.TileUrlFunction.createFromTileUrlFunctions = function(tileUrlFunctions) {
|
||||||
return function(tileCoord) {
|
return function(tileCoord) {
|
||||||
var index = goog.math.modulo(tileCoord.hash(), tileUrlFunctions.length);
|
if (goog.isNull(tileCoord)) {
|
||||||
return tileUrlFunctions[index](tileCoord);
|
return undefined;
|
||||||
|
} else {
|
||||||
|
var index = goog.math.modulo(tileCoord.hash(), tileUrlFunctions.length);
|
||||||
|
return tileUrlFunctions[index](tileCoord);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -54,6 +62,10 @@ ol.TileUrlFunction.createFromTemplates = function(templates) {
|
|||||||
ol.TileUrlFunction.withTileCoordTransform =
|
ol.TileUrlFunction.withTileCoordTransform =
|
||||||
function(transform, tileUrlFunction) {
|
function(transform, tileUrlFunction) {
|
||||||
return function(tileCoord) {
|
return function(tileCoord) {
|
||||||
return tileUrlFunction(transform(tileCoord));
|
if (goog.isNull(tileCoord)) {
|
||||||
|
return undefined;
|
||||||
|
} else {
|
||||||
|
return tileUrlFunction(transform(tileCoord));
|
||||||
|
}
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ goog.require('ol.TileUrlFunction');
|
|||||||
function testCreateFromTemplate() {
|
function testCreateFromTemplate() {
|
||||||
var tileUrl = ol.TileUrlFunction.createFromTemplate('{z}/{x}/{y}');
|
var tileUrl = ol.TileUrlFunction.createFromTemplate('{z}/{x}/{y}');
|
||||||
assertEquals('3/2/1', tileUrl(new ol.TileCoord(3, 2, 1)));
|
assertEquals('3/2/1', tileUrl(new ol.TileCoord(3, 2, 1)));
|
||||||
|
assertUndefined(tileUrl(null));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -16,6 +17,7 @@ function testWithTileCoordTransform() {
|
|||||||
},
|
},
|
||||||
ol.TileUrlFunction.createFromTemplate('{z}/{x}/{y}'));
|
ol.TileUrlFunction.createFromTemplate('{z}/{x}/{y}'));
|
||||||
assertEquals('3/2/1', tileUrl(new ol.TileCoord(3, 2, -1)));
|
assertEquals('3/2/1', tileUrl(new ol.TileCoord(3, 2, -1)));
|
||||||
|
assertUndefined(tileUrl(null));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -27,4 +29,5 @@ function testCreateFromTileUrlFunctions() {
|
|||||||
var tileUrl1 = tileUrl(new ol.TileCoord(1, 0, 0));
|
var tileUrl1 = tileUrl(new ol.TileCoord(1, 0, 0));
|
||||||
var tileUrl2 = tileUrl(new ol.TileCoord(1, 0, 1));
|
var tileUrl2 = tileUrl(new ol.TileCoord(1, 0, 1));
|
||||||
assertTrue(tileUrl1 != tileUrl2);
|
assertTrue(tileUrl1 != tileUrl2);
|
||||||
|
assertUndefined(tileUrl(null));
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user