index.js
function downloadSublayerData(visJson, layerIndex, sublayerIndex, dest, callback) {
    var layer = visJson.layers[layerIndex],
        sublayer = layer.options.layer_definition.layers[sublayerIndex];

    (0, _mkdirp2['default'])(_path2['default'].dirname(dest), function () {
        var dataFile = _fs2['default'].createWriteStream(dest).on('close', function () {
            if (callback) {
                callback();
            }
        });

        var req = (0, _request2['default'])({
            url: getLayerSqlUrl(layer),
            qs: {
                format: 'GeoJSON',
                q: getSublayerSql(sublayer)
            }
        });

        req.pipe(dataFile);

        // Show progress as file downloads
        req.on('response', function (res) {
            var len = parseInt(res.headers['content-length'], 10);
            var bar = new _progress2['default']('  downloading [:bar] :percent :etas', {
                complete: '=',
                incomplete: ' ',
                width: 20,
                total: len
            });

            res.on('data', function (chunk) {
                bar.tick(chunk.length);
            });

            res.on('end', function (chunk) {
                console.log('\n');
            });
        });
    });
}
function downloadSublayerData(visJson, layerIndex, sublayerIndex, dest, callback) {
    var layer = visJson.layers[layerIndex],
        sublayer = layer.options.layer_definition.layers[sublayerIndex];

    (0, _mkdirp2['default'])(_path2['default'].dirname(dest), function () {
        var dataFile = _fs2['default'].createWriteStream(dest).on('close', function () {
            if (callback) {
                callback();
            }
        });

        var req = (0, _request2['default'])({
            url: getLayerSqlUrl(layer),
            qs: {
                format: 'GeoJSON',
                q: getSublayerSql(sublayer)
            }
        });

        req.pipe(dataFile);

        // Show progress as file downloads
        req.on('response', function (res) {
            var len = parseInt(res.headers['content-length'], 10);
            var bar = new _progress2['default']('  downloading [:bar] :percent :etas', {
                complete: '=',
                incomplete: ' ',
                width: 20,
                total: len
            });

            res.on('data', function (chunk) {
                bar.tick(chunk.length);
            });

            res.on('end', function (chunk) {
                console.log('\n');
            });
        });
    });
}
function downloadSublayerData ( visJson , layerIndex , sublayerIndex , dest , callback ) { var layer = visJson . layers [ layerIndex ] , sublayer = layer . options . layer_definition . layers [ sublayerIndex ] ; ( 0 , _mkdirp2 [ 'default' ] ) ( _path2 [ 'default' ] . dirname ( dest ) , function ( ) { var dataFile = _fs2 [ 'default' ] . createWriteStream ( dest ) . on ( 'close' , function ( ) { if ( callback ) { callback ( ) ; } } ) ; var req = ( 0 , _request2 [ 'default' ] ) ( { url : getLayerSqlUrl ( layer ) , qs : { format : 'GeoJSON' , q : getSublayerSql ( sublayer ) } } ) ; req . pipe ( dataFile ) ; // Show progress as file downloads req . on ( 'response' , function ( res ) { var len = parseInt ( res . headers [ 'content-length' ] , 10 ) ; var bar = new _progress2 [ 'default' ] ( '  downloading [:bar] :percent :etas' , { complete : '=' , incomplete : ' ' , width : 20 , total : len } ) ; res . on ( 'data' , function ( chunk ) { bar . tick ( chunk . length ) ; } ) ; res . on ( 'end' , function ( chunk ) { console . log ( '\n' ) ; } ) ; } ) ; } ) ; }
Download the data for a single sublayer.

@param {Object} visJson the visualization's JSON
@param {Number} layerIndex the index of the layer
@param {Number} sublayerIndex the index of the sublayer
@param {String} dest the directory to save the sublayer's data in
@param {Function} callback called on success
Download the data for a single sublayer .