-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgeoreactor.js
58 lines (48 loc) · 1.65 KB
/
georeactor.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
#! /usr/bin/env node
const fs = require('fs');
const program = require('commander');
const toTopoJSON = require('to-topojson').convertFile;
const knownToTopoJSON = require('to-topojson').convertFileWithFormat;
var mapConfig = {
div: "map",
data: []
};
program
.version('0.6.0')
.arguments('<sourceFile>')
.option('-l --label', 'include label', /(.*)/, false)
.option('-f --format <format>', 'format of source file', /^(GeoJSON|TopoJSON|SHP|KML)$/i, '')
.option('-m --map <mapType>', '(Google or Leaflet)', /^(google|leaflet)$/i, 'leaflet')
.option('-d --div <divID>', 'id of map container', /(.*)/, 'map')
.parse(process.argv);
if (!program.args.length) {
console.error('Did not include a file name! Run georeactor --help');
} else {
var sourceFile = program.args[0];
function next (err) {
if (err) {
console.error('The conversion process had an error:');
console.log(JSON.stringify(err));
return;
}
mapConfig.map = program.map;
mapConfig.div = program.div;
mapConfig.data.push('mapdata.topojson');
saveMapWithConfig(mapConfig);
}
if (program.format) {
knownToTopoJSON(sourceFile, program.format, 'mapdata.topojson', next, console.log, program.label);
} else {
toTopoJSON(sourceFile, 'mapdata.topojson', next, console.log, program.label);
}
}
function saveMapWithConfig(mapConfig) {
console.log(mapConfig);
if (mapConfig.map === 'google') {
console.log('saving Google Maps API version');
} else if (mapConfig.map === 'leaflet') {
console.log('saving Leaflet + OSM version');
} else {
console.log('Must use "google" or "leaflet" - other map viewers not yet supported');
}
}