-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtiler.js
91 lines (81 loc) · 3.07 KB
/
tiler.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
var Windshaft = require('windshaft'),
fs = require('fs');
var dbUser = process.env.DB_USER || 'transit_access',
dbPass = process.env.DB_PASSWORD || 'transit_access',
dbHost = process.env.DB_HOST || 'localhost',
dbName = process.env.DB_NAME || 'access',
dbPort = process.env.DB_PORT || '5432',
redisHost = process.env.REDIS_HOST || 'localhost',
redisPort = process.env.REDIS_PORT || '6379';
var psets = {
'cornerstores.geo': 'cornerstore_access_pct_rank',
'headstart.geo': 'headstart_access_pct_rank',
'healthcare.geo': 'healthcare_access_pct_rank',
'rec.geo': 'rec_access_pct_rank',
'playgrounds.geo': 'park_access_pct_rank'
};
function getStyle(pset) {
var baeStyleStart = '#philly_block_access {';
var baseStyleRest = [
'polygon-opacity: 0.25;',
'line-opacity: 0.4;',
'}'].join('');
var blues = ['#ffffff','#f7fbff','#deebf7','#c6dbef','#9ecae1','#6baed6','#4292c6','#2171b5','#08519c','#08306b'];
if (!psets.hasOwnProperty(pset)) {
console.error('unknown pointset ' + pset);
return baeStyleStart + baseStyleRest;
}
var style = baeStyleStart;
i = 0;
for (i = 0; i < blues.length; i++) {
style += '[' + psets[pset] + ' >= ' + (i * 10) + '] { polygon-fill: ' + blues[i] + '; line-color: ' + blues[i] + '}';
}
return style + baseStyleRest;
}
var config = {
base_url: '/tiles/:pset',
base_url_notable: '/tiles',
grainstore: {
datasource: {
user: dbUser,
host: dbHost,
port: dbPort,
password: dbPass,
geometry_field: 'geom_wm',
srid: 3857
}
},
renderCache: {
ttl: 60000, // seconds
},
mapnik: {
metatile: 4,
bufferSize: 64,
},
redis: {
host: redisHost,
port: redisPort
},
enable_cors: true,
req2params: function(req, callback) {
try {
req.params.table = 'philly_block_access';
req.params.dbname = dbName;
req.params.style = getStyle(req.params.pset);
req.params.interactivity = ['geoid10,geojson,cornerstore_access_pct_rank,headstart_access_pct_rank,healthcare_access_pct_rank,',
'daycare_access_pct_rank,playground_access_pct_rank,rec_access_pct_rank,park_access_pct_rank,',
'recap_10,households,median_commute_distance,employment_access_index,local_job_density,local_retail_job_density,',
'retail_access_index,pct_renters,median_income_owners,median_income_renters,daycare,pov_idx,lbr_idx,promise_neighborhood,',
'choice_neighborhood,parks,cornerstore_access,headstart_access,healthcare_access,daycare_access,playground_access,',
'rec_access,park_access'
].join('');
callback(null, req);
} catch(err) {
callback(err, null);
}
}
};
// Initialize tile server on port 4000
var ws = new Windshaft.Server(config);
ws.listen(4000);
console.log('Starting Windshaft tiler on http://localhost:4000' + config.base_url + '/:z/:x/:y.*');