From 3cb1d9f64f6bc331125583659dcfdcd80cdb9e09 Mon Sep 17 00:00:00 2001 From: Tom Payne Date: Mon, 6 Aug 2012 15:50:12 +0200 Subject: [PATCH] Add convenient syntax for specifying multiple tile servers --- src/ol/tile/tileurlfunction.js | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/src/ol/tile/tileurlfunction.js b/src/ol/tile/tileurlfunction.js index 6a68d92821..03a3c32561 100644 --- a/src/ol/tile/tileurlfunction.js +++ b/src/ol/tile/tileurlfunction.js @@ -16,15 +16,28 @@ ol.TileUrlFunctionType; * @return {ol.TileUrlFunctionType} Tile URL function. */ ol.TileUrlFunction.createFromTemplate = function(template) { - return function(tileCoord) { - if (goog.isNull(tileCoord)) { - return undefined; - } else { - return template.replace('{z}', tileCoord.z) - .replace('{x}', tileCoord.x) - .replace('{y}', tileCoord.y); + var match = + /\{(\d)-(\d)\}/.exec(template) || /\{([a-z])-([a-z])\}/.exec(template); + if (match) { + var templates = []; + var startCharCode = match[1].charCodeAt(0); + var stopCharCode = match[2].charCodeAt(0); + 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); + } + }; + } };