-
Notifications
You must be signed in to change notification settings - Fork 0
/
generate_circles.js
77 lines (69 loc) · 1.9 KB
/
generate_circles.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
71
72
73
74
75
76
77
const { execSync } = require("child_process");
const config = require('./config')
/*
************* Non modifiable code below *************
*/
const placemark_list = config.radius_list.reverse().map((radius, index) => {
const output = execSync(
`ruby generate_circle_kml.rb ${config.location.longitude} ${config.location.latitude} ${radius} ${config.vertices}`
).toString();
const placemark =
`
<Placemark>
<name>${radius}m</name>
<styleUrl>#polygon-${index}</styleUrl>
${output}
</Placemark>`;
return placemark;
}).join("\n");
const style_list = config.style_colors.reverse().map((color_table, index) => {
const style =
`
<Style id="polygon-${index}-normal">
<LineStyle>
<color>${color_table[0].toString(16)}</color>
<width>2</width>
</LineStyle>
<PolyStyle>
<color>${color_table[1].toString(16)}</color>
<fill>1</fill>
<outline>1</outline>
</PolyStyle>
</Style>
<Style id="polygon-${index}-highlight">
<LineStyle>
<color>${color_table[0].toString(16)}</color>
<width>2.8</width>
</LineStyle>
<PolyStyle>
<color>${color_table[1].toString(16)}</color>
<fill>1</fill>
<outline>1</outline>
</PolyStyle>
</Style>
<StyleMap id="polygon-${index}">
<Pair>
<key>normal</key>
<styleUrl>#polygon-${index}-normal</styleUrl>
</Pair>
<Pair>
<key>highlight</key>
<styleUrl>#polygon-${index}-highlight</styleUrl>
</Pair>
</StyleMap>`;
return style;
}).join("\n");
const kmlOutput = `<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://www.opengis.net/kml/2.2">
<Document>
<name>${config.location.name}</name>
<description/>
${style_list}
<Folder>
<name>${config.folder_name}</name>
${placemark_list}
</Folder>
</Document>
</kml>
`;
console.log(kmlOutput);