Created
March 12, 2011 02:08
-
-
Save springmeyer/866959 to your computer and use it in GitHub Desktop.
test seed script for tilelive
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env node | |
// To test run from tilelive.js master checkout: | |
// ./bin/node ./bin/carto files/project/k12_county_stats/k12_county_stats.mml > k12_county_stats.xml | |
// time ./bin/node ./seedtest/tileseed.js k12_county_stats.xml 1 CNTY_FIPS k12_z12_test.mbtiles | |
var sys = require('sys'), | |
Step = require('step'), | |
TileBatch = require('tilelive').TileBatch; | |
var args = process.argv.slice(1); | |
if (!args[1]) { | |
sys.puts("seed.js: please provide an input .xml path"); | |
process.exit(1); | |
} | |
var stylesheet = args[1]; | |
if (!args[2]) { | |
sys.puts("seed.js: please provide a layer index for interactivity"); | |
process.exit(1); | |
} | |
var layer_idx = parseInt(args[2]); | |
if (!args[3]) { | |
sys.puts("seed.js: please provide a field name for interactivity"); | |
process.exit(1); | |
} | |
var join_field = args[3]; | |
if (!args[4]) { | |
sys.puts("seed.js: please provide an output mbtiles name"); | |
process.exit(1); | |
} | |
var mbtile_file = args[4]; | |
var batch = new TileBatch({ | |
filepath: mbtile_file, | |
batchsize: 100, | |
bbox: [ | |
-20037500, | |
-20037500, | |
20037500, | |
20037500 | |
], | |
format: 'png', | |
minzoom: 0, | |
maxzoom: 12, | |
datasource: stylesheet, | |
language: 'xml', | |
interactivity: { | |
key_name: join_field, | |
layer: layer_idx | |
}, | |
metadata: { | |
name: mbtile_file, | |
type: 'baselayer', | |
description: mbtile_file, | |
version: '1.1', | |
formatter: 'function(options, data) {' | |
+ ' return "<strong>" + data.COUNTY + ", " + data.STATE + "</strong><br />"' | |
+ ' + data.SCHOOLS + " schools<br />"' | |
+ ' + data.STUDENTS + " students<br />"' | |
+ ' + data.PT_RATIO + " pupils per teacher"' | |
+ ' }' | |
} | |
}); | |
Step( | |
function() { | |
console.log('setup'); | |
batch.setup(function(err) { | |
if (err) throw err; | |
this(); | |
}.bind(this)); | |
}, | |
function(err) { | |
console.log('fillGridData'); | |
if (err) throw err; | |
if (!batch.options.interactivity) return this(); | |
batch.fillGridData(function(err, tiles) { | |
if (err) throw err; | |
this(); | |
}.bind(this)); | |
}, | |
function(err) { | |
console.log('renderChunk'); | |
if (err) throw err; | |
var next = this; | |
var end = function(err, tiles) { | |
if (err) throw err; | |
next(err); | |
}; | |
var render = function() { | |
process.nextTick(function() { | |
batch.renderChunk(function(err, tiles) { | |
if (err) { | |
console.log('err: ' + err + ' ' + tiles); | |
throw err; | |
} | |
if (!tiles) { | |
console.log('finished ' + err + ' ' + tiles); | |
return end(err, tiles); | |
} | |
render(); | |
}); | |
}); | |
}; | |
render(); | |
}, | |
function(err) { | |
console.log('finish'); | |
if (err) throw err; | |
batch.finish(this); | |
}, | |
function(err) { | |
console.log('done'); | |
if (err) throw err; | |
} | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment