Add convenient syntax for specifying multiple tile servers
This commit is contained in:
@@ -16,15 +16,28 @@ 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) {
|
var match =
|
||||||
if (goog.isNull(tileCoord)) {
|
/\{(\d)-(\d)\}/.exec(template) || /\{([a-z])-([a-z])\}/.exec(template);
|
||||||
return undefined;
|
if (match) {
|
||||||
} else {
|
var templates = [];
|
||||||
return template.replace('{z}', tileCoord.z)
|
var startCharCode = match[1].charCodeAt(0);
|
||||||
.replace('{x}', tileCoord.x)
|
var stopCharCode = match[2].charCodeAt(0);
|
||||||
.replace('{y}', tileCoord.y);
|
var charCode;
|
||||||
|
for (charCode = startCharCode; charCode <= stopCharCode; ++charCode) {
|
||||||
|
templates.push(template.replace(match[0], String.fromCharCode(charCode)));
|
||||||
}
|
}
|
||||||
};
|
return ol.TileUrlFunction.createFromTemplates(templates);
|
||||||
|
} else {
|
||||||
|
return function(tileCoord) {
|
||||||
|
if (goog.isNull(tileCoord)) {
|
||||||
|
return undefined;
|
||||||
|
} else {
|
||||||
|
return template.replace('{z}', tileCoord.z)
|
||||||
|
.replace('{x}', tileCoord.x)
|
||||||
|
.replace('{y}', tileCoord.y);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user