-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathgenerateBuildConfig.js
64 lines (49 loc) · 1.72 KB
/
generateBuildConfig.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
'use strict';
const fs = require('fs');
const mapnik = require('mapnik');
const swig = require('swig');
const buildConfig = require('./lib/buildConfig');
const ocdidMappingProcessor = require('./lib/ocdidMappingProcessor');
mapnik.register_default_input_plugins();
const HIGHLIGHT_COLORS = {
federal: '#ffaf50',
state: '#0196b4',
local: '#3dc489'
};
// check if a feature matches any of the attributes in the skip list
// output collection
const tiles = [];
buildConfig().eachMap((mapName, mapConfig) => {
const buildConfigDir = 'build/' + mapName;
console.log('Generating config ' + buildConfigDir);
if (!fs.existsSync(buildConfigDir)) {
fs.mkdirSync(buildConfigDir);
}
ocdidMappingProcessor.generateOcdIdMaps(mapName, mapConfig);
mapConfig.eachFeature((feature, shapefile) => {
const datum = feature.attributes();
const renderAttributes = mapConfig.render_each.map((attr) => datum[attr]);
const tileName = renderAttributes.join('-');
// skip rendering of tiles without an ocdid, since we won't represent
// them on brigade anywhere
const ocdid = ocdidMappingProcessor.getTileOCDID(renderAttributes, mapName);
if (!ocdid) {
return;
}
for (const level of mapConfig.levels) {
const xmlPath = buildConfigDir + '/' + tileName + '_' + level + '.xml';
datum.highlightColor = HIGHLIGHT_COLORS[level];
datum.shapefile = shapefile;
fs.writeFileSync(xmlPath,
swig.renderFile('config/' + mapName + '/stylesheet.xml.swig', datum)
);
tiles.push({
xmlPath: xmlPath,
ocdid: ocdid,
level: level,
extent: mapConfig.extent(feature, ocdid),
});
}
});
});
fs.writeFileSync('build/tiles.json', JSON.stringify(tiles));