-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
52 lines (45 loc) · 1.72 KB
/
main.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
var fs = require('fs');
var handlebars = require('handlebars');
var image_handler = require('./lib/image_handler');
var kml_extractor = require('./lib/kml_extractor');
var kml_writer = require('./lib/kml_writer');
var path = require('path');
var pngparse = require("pngparse");
var Q = require('q');
var xml2js = require('xml2js');
var $_ = require('underscore');
var src_kml;
function init () {
if (process.argv.length < 3 || process.argv[2].search(/kml/ig) === -1) {
console.log('You must supply the path to a KML file to begin.\n\nUsage: node main.js path_to_kml_file\n');
process.exit(1);
}
src_kml = path.resolve(__dirname, process.argv[2]);
return kml_extractor.parse_file(src_kml);
}
init().then(function (kml_docs) {
var commands = [];
kml_extractor.extract_placemarks();
console.log('converting map');
$_.each(kml_docs, function (kml_doc) {
$_.each(kml_doc.get_placemarks(), function (placemark) {
var src = path.resolve(path.dirname(src_kml), placemark.file);
var chain = image_handler.pdf_to_png(src)
.then(image_handler.get_map_image_borders)
.then(image_handler.cut_map_image)
.then(image_handler.tile_map_image)
.then(function (res) {
placemark.processed_file_data = res;
placemark.create_tile_data();
return true;
});
commands.push(chain);
});
});
return Q.all(commands);
}).then(function () {
console.log('all placemarks processed. generating kml file.');
kml_writer.write('./test_data/test/doc.kml', kml_extractor.get_kml_docs());
}).fail(function (err) {
throw err;
}).done();