Move factorizable code in ol.TileUrlFunction.expandUrl

This commit is contained in:
Bruno Binet
2013-03-12 18:26:43 +01:00
parent c4ab34e4a7
commit 54dfca3419
3 changed files with 48 additions and 15 deletions

View File

@@ -120,3 +120,24 @@ ol.TileUrlFunction.withTileCoordTransform =
}
};
};
/**
* @param {string} url Url.
* @return {Array.<string>} Array of urls.
*/
ol.TileUrlFunction.expandUrl = function(url) {
var urls = [];
var match = /\{(\d)-(\d)\}/.exec(url) || /\{([a-z])-([a-z])\}/.exec(url);
if (match) {
var startCharCode = match[1].charCodeAt(0);
var stopCharCode = match[2].charCodeAt(0);
var charCode;
for (charCode = startCharCode; charCode <= stopCharCode; ++charCode) {
urls.push(url.replace(match[0], String.fromCharCode(charCode)));
}
} else {
urls.push(url);
}
return urls;
};