-
Notifications
You must be signed in to change notification settings - Fork 4
/
index.js
70 lines (53 loc) · 1.63 KB
/
index.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#!/usr/bin/env node
var path = require("path"),
fs = require("fs-extra"),
validate = require("./src/validate");
const params = require("./src/options.js")
module.exports = function vtile(args) {
const opts = createOptionsObject(params)
if (args) {
var pkeys = Object.keys(opts);
for (var k in args) {
opts[k] = args[k];
opts[pkeys[pkeys.indexOf(k) + 1]] = args[k]
}
}
opts.w = (opts.w === true || opts.w === "true" || opts.write === true || opts.write === "true") ? true : false;
opts.write = opts.w;
// console.log(opts);
if (opts.h || opts.help) {
console.log("vtile creates vector tiles in mvt format from a geojson file(s) \n \n Usage: command [options]");
options.print();
process.exit();
}
if (opts.z < 0) {
throw error
}
if (opts.Z > 20) {
console.log("Very high zoom level detected, stopping application. A zoom level of 14 to 16 is likely sufficient.");
throw error
}
var tileDirectory = path.resolve(process.cwd(), opts.t);
console.log(tileDirectory);
if (!fs.existsSync(tileDirectory)) {
fs.mkdirSync(tileDirectory);
}
if (!opts.i) {
var geojsonDirectory = path.resolve(process.cwd(), opts.d);
}
if (opts.i === "") {
fs.readdirSync(geojsonDirectory).forEach(file => {
validate(path.resolve(geojsonDirectory, file), tileDirectory, opts)
});
}else{
validate(opts.i, tileDirectory, opts)
}
}
function createOptionsObject(array) {
const options = {};
array.forEach(a => {
if (a.name != "help") options[a.name] = a.default;
if (a.name != "help") options[a.abbr] = a.default;
})
return options
}