-
Notifications
You must be signed in to change notification settings - Fork 3
/
sld2mapbox.js
32 lines (27 loc) · 1012 Bytes
/
sld2mapbox.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
let fs = require('fs');
let parseXmlFile = require ('./parsexmlfile.js')
let parseSld = require('./parsesld.js');
let toMapboxStyle = require('./tomapboxstyle.js');
let beautify = require('json-beautify');
async function sld2Mapbox(sldFilename, outputFilename) {
try {
fs.unlinkSync(outputFilename);
let parsedXml = await parseXmlFile(sldFilename);
let parsedRules = parseSld(parsedXml);
let sldStyleName = parsedXml.StyledLayerDescriptor.NamedLayer[0].Name;
let mapboxStyle = toMapboxStyle(sldStyleName, parsedRules);
fs.writeFileSync(outputFilename, beautify(mapboxStyle,null,2,100));
} catch (err) {
console.error(err.message);
process.exit(1);
}
}
function usage() {
console.log('usage: "node sld2mapbox.js sldfilename"');
}
let sldFilename = process.argv.length > 2 ? process.argv[2] : undefined;
if (!sldFilename) {
usage();
process.exit(1);
}
sld2Mapbox(sldFilename, 'output.json')