Skip to content

Commit

Permalink
Added support for multiple url templates.
Browse files Browse the repository at this point in the history
  • Loading branch information
brianreavis committed Feb 17, 2015
1 parent 0e00869 commit 5b7832e
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 18 deletions.
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ $ npm install tilemantle -g
```
$ tilemantle -h
Usage: tilemantle <url> [options]
Usage: tilemantle <url> [<url> ...] [options]
Options:
--version Display version number
Expand All @@ -20,10 +20,10 @@ Options:
-e, --extent Extent of region in the form of: nw_lat,nw_lon,se_lat,se_lon
-p, --point Center of region (use in conjunction with -b)
-b, --buffer Buffer point/geometry by an amount. Affix units at end: mi,km
-d, --delay Delay between requests. Affix units at end: ms,s
-m, --method HTTP method to use to fetch tiles
--ua User-Agent for requests
-c, --concurrency Number of tiles to request simultaneously
-d, --delay Delay between requests. Affix units at end: ms,s
-m, --method HTTP method to use to fetch tiles
-H, --header Set request header
-c, --concurrency Number of tiles to request simultaneously
```

### Usage
Expand Down
33 changes: 20 additions & 13 deletions bin/tilemantle.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ var filesize = function(bytes) {
};

var argv = require('yargs')
.usage('Usage: $0 <url> [options]')
.usage('Usage: $0 <url> [<url> ...] [options]')
.version(pkg.version+'\n', 'version', 'Display version number')
.alias('h', 'help').describe('h', 'Display usage information').boolean('h')
.alias('l', 'list').describe('l', 'Don\'t perform any requests, just list all tile URLs').boolean('l')
Expand Down Expand Up @@ -50,22 +50,25 @@ if (argv.help) {
}

// parse options
var urltemplate = argv._[2];
var urltemplates = argv._.slice(2);
var validateurlparam = function(template, param) {
if (template.indexOf(param) === -1) {
displayHelp();
console.error('URL missing ' + param + ' parameter');
process.exit(1);
}
};
if (!/^https?\:/.test(urltemplate)) {
displayHelp();
console.error('No url template provided');
process.exit(1);
}
validateurlparam(urltemplate, '{x}');
validateurlparam(urltemplate, '{y}');
validateurlparam(urltemplate, '{z}');

urltemplates.forEach(function(template) {
if (!/^https?\:/.test(template)) {
displayHelp();
console.error('No url template provided');
process.exit(1);
}
validateurlparam(template, '{x}');
validateurlparam(template, '{y}');
validateurlparam(template, '{z}');
});

// execute
var count_succeeded = 0;
Expand Down Expand Up @@ -142,11 +145,15 @@ async.series([
var result = [];
return result.concat.apply(result, groups);
}
function formatURL(xyz) {
return urltemplate.replace(/\{x\}/g, xyz[0]).replace(/\{y\}/g, xyz[1]).replace(/\{z\}/g, xyz[2]);
function buildURLs(xyz) {
urltemplates.forEach(function(template) {
urls.push(template.replace(/\{x\}/g, xyz[0]).replace(/\{y\}/g, xyz[1]).replace(/\{z\}/g, xyz[2]));
});
}

var urls = buildTileList(geojson, zooms).map(formatURL);
var urls = [];
buildTileList(geojson, zooms).forEach(buildURLs);

if (argv.list) {
for (var i = 0, n = urls.length; i < n; i++) {
console.log(urls[i]);
Expand Down

0 comments on commit 5b7832e

Please sign in to comment.