Major refactoring of the urls (#5)

This commit is contained in:
Petr Sloup
2016-03-10 18:26:26 +01:00
parent 6f644a4c03
commit 4c40700bac
6 changed files with 180 additions and 94 deletions

View File

@@ -1,7 +1,6 @@
'use strict';
module.exports.getTileUrls = function(
protocol, domains, host, path, tilePath, format, key) {
module.exports.getTileUrls = function(req, domains, path, format) {
if (domains) {
if (domains.constructor === String && domains.length > 0) {
@@ -9,19 +8,16 @@ module.exports.getTileUrls = function(
}
}
if (!domains || domains.length == 0) {
domains = [host];
domains = [req.headers.host];
}
var key = req.query.key;
var query = (key && key.length > 0) ? ('?key=' + key) : '';
if (path == '/') {
path = '';
}
var uris = [];
domains.forEach(function(domain) {
uris.push(protocol + '://' + domain + path +
tilePath.replace('{format}', format).replace(/\/+/g, '/') +
query);
uris.push(req.protocol + '://' + domain + '/' + path +
'/{z}/{x}/{y}.' + format + query);
});
return uris;