|
|
@ -1,9 +1,52 @@ |
|
|
|
const tabs = require('modulekit-tabs') |
|
|
|
const async = require('async') |
|
|
|
const chunkSplit = require('./chunkSplit') |
|
|
|
|
|
|
|
let tab |
|
|
|
let formExport |
|
|
|
|
|
|
|
function prepareDownload () { |
|
|
|
function prepareDownload (callback) { |
|
|
|
let conf = formExport.get_data() |
|
|
|
let result = [] |
|
|
|
|
|
|
|
global.baseCategory.allMapFeatures((err, data) => { |
|
|
|
console.log(data) |
|
|
|
|
|
|
|
let chunks = chunkSplit(data, 1000) |
|
|
|
|
|
|
|
async.eachLimit( |
|
|
|
chunks, |
|
|
|
1, |
|
|
|
(chunk, done) => { |
|
|
|
result = result.concat(chunk.map(ob => { |
|
|
|
switch (conf.type) { |
|
|
|
case 'geojson': |
|
|
|
return ob.object.GeoJSON(conf) |
|
|
|
} |
|
|
|
})) |
|
|
|
|
|
|
|
global.setTimeout(done, 0) |
|
|
|
}, |
|
|
|
(err) => { |
|
|
|
if (err) { |
|
|
|
return callback(err) |
|
|
|
} |
|
|
|
|
|
|
|
switch (conf.type) { |
|
|
|
case 'geojson': |
|
|
|
result = { |
|
|
|
type: 'FeatureCollection', |
|
|
|
features: result |
|
|
|
} |
|
|
|
result = JSON.stringify(result, null, ' ') |
|
|
|
} |
|
|
|
|
|
|
|
console.log(result) |
|
|
|
|
|
|
|
callback() |
|
|
|
} |
|
|
|
) |
|
|
|
}) |
|
|
|
} |
|
|
|
|
|
|
|
register_hook('init', function () { |
|
|
@ -35,8 +78,13 @@ register_hook('init', function () { |
|
|
|
submit.value = lang('export-prepare') |
|
|
|
submit.onclick = () => { |
|
|
|
submit.setAttribute('disabled', 'disabled') |
|
|
|
alert('Download') |
|
|
|
submit.removeAttribute('disabled') |
|
|
|
prepareDownload((err) => { |
|
|
|
if (err) { |
|
|
|
alert(err) |
|
|
|
} |
|
|
|
|
|
|
|
submit.removeAttribute('disabled') |
|
|
|
}) |
|
|
|
} |
|
|
|
tab.content.appendChild(submit) |
|
|
|
|
|
|
|